Re:What's New in JavaScript for 2019
by reverentgeek on Tuesday January 22, 2019 @04:05PM
(#18972456)
Here's the FAQ on the private syntax: https://github.com/tc39/proposal-class-fields/blob/master/PR...
Ok 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 #
Re:What's New in JavaScript for 2019
by singularity2001 on Wednesday January 23, 2019 @07:38AM
(#18977660)
Yes 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}`)
}
}
If fields in class definitions are incorporated I would like it to simultaneously make the field names in scope for any methods within the class definition.
Adding this feature would allow for much tidier method bodies since there is now enough information to imply this.fieldName from fieldName alone.