3 ms·
Why not use the private/public keywords like in TypeScript? Was this # thing voted by the community or something?
by 21 8y ago
Why not use the private/public keywords like in TypeScript?
Was this # thing voted by the community or something?
- lucideer 8y agoThe justification is that they needed a unique accessor, because: - attempting to access a non-existent private property using `this.prop` would create a public property "prop" in JS, which they claim would be a source of bugs. - they also wanted to allow creating a public property on a subclass with the same name as a private property on a parent class—having the accessors the same could be confusing. That said, they could still have had keywords for definition with an alternative accessor. # is definitely not idiomatic; it's extremely ugly.
- mathias 8y agoThe article links to the explanation by the proposal champions: https://github.com/tc39/proposal-class-fields/blob/master/PRIVATE_SYNTAX_FAQ.md#why-arent-declarations-private-x https://github.com/tc39/proposal-class-fields/blob/master/PR...