function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function () {
return `${this.name} makes a sound`;
};
function Dog(name) {
Animal.call(this, name);
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function () {
return `${Animal.prototype.speak.call(this)} (bark)`;
};
const d = new Dog('Rex');
console.log(
d.speak(),
d instanceof Animal,
d.constructor === Dog,
Object.getPrototypeOf(d) === Dog.prototype
);
export {}; Post #3392
2.39K
CHALLENGE
- 👍 3
- ❤ 1
- 🔥 1