How to declare private attribute and methods in classes?
class transformer {
name: 'Optimus Prime';
#previousName: 'Orion Pax'; // private attribute
rollOut() {
//...
}
// private method
#transform() {
//...
}
}
August 2nd, 2022
Until now, the convention was to use the _
for private attributes and methods. However, this had not been able to prevent the abuse.
To declare a private attribute or method, just put a #
in front of it.