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

I don’t understand how the eat function is linked to Bear or Cat? Animal isn’t named as a supertype of either so how are they linked and thus how is the eat function applied to the other to subtypes like its meant to be?

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");
}
}

.eat()

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.41

Challenge: Object Oriented Programming - Use Inheritance So You Don’t Repeat Yourself

Link to the challenge:

Yes I noticed this as soon as i posted it. My bad

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.