JSFiddle - React, Tailwind, and code Playground
JavaScript
var Animal = function() {}
Animal.prototype = {
"speak": function() {
alert("RawR")
}
}
var Person = function(name) {
this.changeCount = 0
this.name = name
}
Person.prototype = Animal.prototype;
Object.defineProperties(Person.prototype, {
"name": {
get: function() { return this._name },
set: function(name) {
this.changeCount++
this._name = name
}
}
})
var p = new Person("John Doe")
console.log(p.name)
console.log(p.changeCount)
p.name = "John Smith"
console.log(p.name)
console.log(p.changeCount)
p.speak()