Tell us what’s happening:
My question is, in both Cat.prototype and Dog.prototype, if I change the constructor to Animal instead of Cat and Dog, It still works
Help me to clear my concept
Your code so far
function Cat(name) {
this.name = name;
}
Cat.prototype = {
constructor: Cat,
eat: function() {
console.log("nom nom nom");
}
};
function Bear(name) {
this.name = name;
}
Bear.prototype = {
constructor: Bear,
eat: function() {
console.log("nom nom nom");
}
};
function Animal() { }
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
Cat.prototype = {
constructor: Animal
};
Bear.prototype = {
constructor: Animal
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Challenge Information:
Object Oriented Programming - Use Inheritance So You Don’t Repeat Yourself