I want to block the assignment of properties only by the set name function because I want to do some formatting or validation before, look the example:
class Animal {
construct(name){
this.name = name;
return this;
}
setName(name){
this.name = name;
}
getName(){
return this.name;
}
}
class Dog extends Animal {
constructor(name){
super(name);
return this;
}
setName(name){
this.name = name.charAt(0).toUpperCase() + name.slice(1);
}
}
const dog = new Dog();
dog.setName('joe');
console.log(dog.getName()); //Joe
dog.name = 'Bill'; // I wish this type of assignment would not work
console.log(dog.getName()); //Bill
It is possible to do this or something similar ?