Object Oriented Programming: Use Inheritance So You Don't Repeat Yourself - Help

Tell us what’s happening:
I’m able to pass the test but I don’t understand why it works.
How did Cat and Bear automatically become subtypes of Animal?

Your code so far


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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Use Inheritance So You Don’t Repeat Yourself

Link to the challenge:

In that code none of Bird nor Dog knows anything about Animal. Continue with the next challenge, there explains how to Bird and Dog classes can inherit methods from the superclass Animal.

1 Like