Public and private class fields
developers.google.com
Public and private class fields
1–10 of 112 posts
Re: Public and private class fields
#2Re: Public and private class fields
#3Frankly, if this is an issue that you are concerned about, you should really invest the time to learn (and possibly migrate to) TypeScript. Specifically, see their class documentation which already has support for `public`, `private`, and `protected` [1]. (Edit: read @denisw's reply regarding TS. I make this suggestion specifically for TS's compile-time assistance regarding private field access.)
It actually kind of boggles my mind that V8 engineers sat down and agreed that this would be a good design decision. Granted, the article says that they are proposals—is there any way to provide feedback on this? (Edit: https://github.com/tc39/proposal-class-fields/blob/master/PR...)
[1] https://www.typescriptlang.org/docs/handbook/classes.html
Re: Public and private class fields
#4Wow, the '#' prefix is so ugly.
Re: Public and private class fields
#5 let incrementer = () => {
let x = 0;
return { value: () => x, increment: () => x++ };
};
It's like the OO people are determined to forget about the functional concepts that made JS great.Re: Public and private class fields
#6This is Exhibit N for the "the class keyword is ruining Javascript" prosecution. If you want a "private variable" you just use a closure. let incrementer = () => { let x = 0; return { value: () => x, increment: () => x++ }; }; It's like the OO people are determined to forget about the functional concepts that made JS great.
Re: Public and private class fields
#7Re: Public and private class fields
#8Re: Public and private class fields
#9This is Exhibit N for the "the class keyword is ruining Javascript" prosecution. If you want a "private variable" you just use a closure. let incrementer = () => { let x = 0; return { value: () => x, increment: () => x++ }; }; It's like the OO people are determined to forget about the functional concepts that made JS great.
That said, considering how widespread JavaScript is at this point, I think it is in their best interest to cater to more than one programming style.
Re: Public and private class fields
#10I don't understand why public fields need the underscore prefix. Aren't all fields public by default? Why do you need to add a prefix to "hide" public fields?