im having trouble understanding supertype
i cant see where in the code do *Bear and *Cat get their -Animal- inheritance
Your code so far
function Cat(name) { // if cat instance-object is created here
this.name = name; // does this function contain the prototype of -Animal? if so, how do you difference it from any other constructor that doesn't has it
}
Cat.prototype = { // here it calls for it's prent above (?
constructor: Cat, // and checks if the parent is Cat (?
};
// i assume they now have the "eat" method but I dont understand where have they inherited it
function Bear(name) {
this.name = name;
}
Bear.prototype = {
constructor: Bear,
};
function Animal() { } // so this function is the supertype, it is a constructor right (? therefore an object
Animal.prototype = { // here it seams to be calling the prototype of the funcion animal which is an object (?)
constructor: Animal, // here it says it was created by the function above "Animal"
eat: function() { // assigns the method to the object
console.log("nom nom nom");
}
};
// thank you for your time
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Challenge: Object Oriented Programming - Use Inheritance So You Don’t Repeat Yourself
Link to the challenge: