Wednesday, August 31, 2022

JavaScript vs TypeScript: class private members

After IE was "retired", the default features of JavaScript are "almost" enough for make relatively complex and safe programs. On the other side, TypeScript provide full spectrum features comparable to compiled programming languages. Well worth of a bit added setup complexity and transpiling time. 

Private class features - JavaScript | MDN

Working with private class features - JavaScript | MDN

class Counter extends HTMLElement {
  #xValue = 0;
  get #x() { return #xValue; }
  set #x(value) {
    this.#xValue = value;
Private Methods and Properties in TypeScript Classes
TypeScript: Documentation - Classes

TypeScript: Documentation - Classes (member visibility)
class A {
private x = 10; protected y: number = 5;
z = 'abc'; // default visibility is "public"

No comments: