ES6 getter and setter how to.
class Animal {
constructor(name) {
this._name = name;
}
get name() {
return 'Animal name is ' + this._name;
}
set name(name) {
this._name = name + '!';
}
}
let cat = new Animal('Cat');
cat.name = 'Kitty'
console.log(cat.name);