|
|
|
|
|
by temporallobe
1198 days ago
|
|
For me, the most awesome and useful change to Javascript has been the addition of private and static modifiers, although the implementation is kinda weird (why use “static” keyword but not “private” and the # sigil instead?). I use both TS and JS professionally but much prefer native JS and use it in my personal projects, however, the closer native JS can get to TS, the better, as I really do appreciate many of it’s features. |
|
Supposedly it's because of this:
> Why isn't access this.x?
> Having a private field named x must not prevent there from being a public field named x, so accessing a private field can't just be a normal lookup.
https://github.com/tc39/proposal-class-fields/blob/main/PRIV...
Combined with this:
> Why aren't declarations private x?
> This sort of declaration is what other languages use (notably Java), and implies that access would be done with this.x. Assuming that isn't the case (see above), in JavaScript this would silently create or access a public field, rather than throwing an error. This is a major potential source of bugs or invisibly making public fields which were intended to be private.
https://github.com/tc39/proposal-class-fields/blob/main/PRIV...
But I still think it's weird.