tgoop.com/javascript/2408
Create:
Last Update:
Last Update:
CHALLENGE
function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function() {
return `${this.name} makes a noise.`;
};
function Dog(name) {
Animal.call(this, name);
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function() {
return `${this.name} barks.`;
};
const animal = new Animal('Rover');
const dog = new Dog('Rex');
console.log(dog instanceof Animal, dog.speak(), animal.speak(), Dog.prototype.isPrototypeOf(dog));
BY JavaScript
Share with your friend now:
tgoop.com/javascript/2408