THE TASK The eat
method is repeated in both Cat
and Bear
. Edit the code in the spirit of DRY by moving the eat
method to the Animal
supertype
.
How does the cat and bear objects inherit the animal properties here? I dont understand.
function Cat(name) {
this.name = name;
}
Cat.prototype = {
constructor: Cat,
};
function Bear(name) {
this.name = name;
}
Bear.prototype = {
constructor: Bear,
};
function Animal() { }
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0
Challenge: Object Oriented Programming - Use Inheritance So You Don’t Repeat Yourself
Link to the challenge: