TC39 passed a draft of ECMAScript private properties on GitHub

Recently, TC39 passed a draft of the ECMAScript syntax feature on GitHub (the JavaScript Class field declaration), which is the class private property modifier “#”. However, this feature has encountered a lot of opposition in the community research.

TC39 – ECMAScript® is responsible for the development of the ECMAScript standard, including Microsoft, Mozilla, Google and other large companies. The overall consideration of the TC39 is that ES5 is basically compatible with ES3, and larger syntax fixes and new features are added, which will be done by JavaScript.next.

The private property modifier “#” is used as follows:

class Counter extends HTMLElement {
  #x = 0;

  clicked() {    this.#x++;
    window.requestAnimationFrame(this.render.bind(this));
  }

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

  connectedCallback() { this.render(); }

  render() {    this.textContent = this.#x.toString();
  }
}
window.customElements.define('num-counter', Counter);

The private properties and methods of a class use the “#” prefix as a modifier, meaning that the property or method scope is limited to the block-level scope of the class, and you cannot reference it outside.

The grammar caused a lot of opposition from the community. In an issue of the draft grammar, someone did a survey showing that the community did not agree with the draft:

The main concerns of the community on this draft include:

  • “#” is the id selector in CSS, and as a private property modifier in JS can cause confusion and reduce code readability;
  • “#” is used as a comment syntax in some programming languages, and it can confuse JS.
  • TypeScript has previously implemented a private property whose modifier is privatethat the implementation inconsistency now creates a cognitive burden.

The TypeScript development team also made it clear that they didn’t like this syntax.

This draft has entered the stage 3 state as early as July 2017. It is challenging to change. The TC39 committee passed because they believe that the committee and the community have reached a consensus on this draft, even if some developers think this An agreement does not exist.

The reason for the committee’s objection to the above findings is that the survey in the GitHub issue area attracted more opponents, and most of the approvers of the draft would not express their opinions in the issue area.

Also, the committee members responded under the issue that they did not use the same implementation as TypeScript and deliberately kept different from TypeScript so as not to deviate from the direction of JS.

Via: TC39