tc39 / proposal-private-methods

Private methods and getter/setters for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=1668
345 stars 37 forks source link

this.#value vs #value - short form of writing #35

Closed lukaszpolowczyk closed 6 years ago

lukaszpolowczyk commented 6 years ago
class Counter extends HTMLElement {
  #xValue = 0;

  get #x() { return #xValue; }
  set #x(value) {
    #xValue = value; 
    window.requestAnimationFrame(#render.bind(this));
  }

  #clicked() {
    #x++;
  }

  constructor() {
    super();
    onclick = #clicked.bind(this);
  }

  connectedCallback() { #render(); }

  #render() {
    textContent = #x.toString();
  }
}
window.customElements.define('num-counter', Counter);
littledan commented 6 years ago

Note, this short form is proposed in https://github.com/littledan/proposal-private-shorthand

littledan commented 6 years ago

Let's continue considering the private shorthand in its own repository.