|
|
|
|
|
by Lerc
2712 days ago
|
|
I tend to agree with the article author about the use of a # (or indeed any punctuation mark) for private fields. I think it is just a personal preference thing though. Is there any publicly available discussion that shows what lead to this decision? 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. class Fish extends Vertebrate {
color = "blue";
constructor (speed) {
super();
this.speed = speed;
if (speed > 5) color = "red" // does not need this.color because color is a class field.
}
}
Fish.prototype.setColor = function (newValue) {
this.color = newValue; // this. is required because this function is outside 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. |
|