|
|
|
|
|
by Klathmon
2712 days ago
|
|
It's not just about keywords, it's about shadowing mostly [1]. For example, what does `this.foo` access in an object? the private property `foo`? the public property `foo`? What about if I'm using your object and put a new property `foo` on it after it's created, then what happens? None of the answers to those questions are really good. If the private shadows the public, then how do you access the public? If it's the other way around, then external users can break your private fields by adding a public of the same name, which kind of defeats the purpose... TypeScript can get away with it because it's not really enforced by the runtime, only the typechecker, so their `private` isn't really private outside of TypeScript. [1] https://github.com/tc39/proposal-class-fields/blob/master/PR... |
|