4 ms·
Here's the FAQ on the private syntax: https://github.com/tc39/proposal-class-fields/blob/master/PRIVATE_SYNTAX_FAQ.md https://github.com/tc39/proposal-class-fie
by reverentgeek 8y ago
Here's the FAQ on the private syntax: https://github.com/tc39/proposal-class-fields/blob/master/PRIVATE_SYNTAX_FAQ.md https://github.com/tc39/proposal-class-fields/blob/master/PR...
- Lerc 8y agoOk reading that I'm going to amend my suggestion above. class fish { color = "blue"; // color is now a name in scope for this class definition #agenda = "Total World Domination" // agenda is now a name in scope for this class definition ... reveal () { console.log("I am a " + color + " Fish " // interpreted as this.color +"seeking " + agenda // interpreted as this.#agenda; } } You can still have this.agenda for public addon fields. But for the private one you can refer to it within the class definition without either this. or #
- singularity2001 8y agoYes please make the syntax simple like this! Even cleaner: class fish { color = "blue"; private agenda = "World Peace" constructor(){ color="red" agenda="Secret World Domination" } reveal () { console.log(`I am a ${color} Fish seeking ${agenda}`) } }