JSFiddle - React, Tailwind, and code Playground
JavaScript
class Pet {
constructor(name) {
this._name = name;
}
get name() {
return this._name;
}
set name(newName) {
this._name = newName;
}
walk() {
console.log(this._name + ' is walking.');
}
}
class Cat extends Pet {
constructor(name, activity) {
super(name);
this._activity = activity;
}
get PetActivity() {
return this._activity;
}
set PetActivity(activity) {
this._activity = activity;
}
writeEating() {
console.log(this._name + ' is cat & she is ' + this._activity + '.');
}
}
let misty = new Pet('Pet');
misty.walk();
let catty = new Cat('Misty', 'eating');
catty.walk();
catty.writeEating();
console.log(catty.name);