Look at the following code:
class Animal() {
constructor(type, name) {
this._type = type;
this._name = name;
}
get type() {
return this._type;
}
get name() {
return this._name;
}
}
If I were to run:
var Dog = new Animal("Dog", "Rover");
console.log(Dog._name);
The console would return the name of my dog without the need to use the `get name() {} that I wrote above. What is the point of getters and setters in Javascript 6 if I can access my object properties directly? Why is the underscore a convention for private properties when it does nothing to privatize them? How can I make my properties private in classes in Javascript using current ecmascript-6 standards?