Supertype(parent) Object

Tell us what’s happening:
Describe your issue in detail here.
How Animal object became supertype(parent) here? Animal object is declared same as Bear and Cat, and how eat() method works for Bear and Cat?

  **Your code so far**
function Cat(name) {
this.name = name;
}


function Bear(name) {
this.name = name;
}


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:102.0) Gecko/20100101 Firefox/102.0

Challenge: Use Inheritance So You Don’t Repeat Yourself

Link to the challenge:

you can notice that the eat method is defined in prototype of Animal class, when you create objects of cat and bear you will assign the prototype of Animal as a value of cat and bear prototype in this way the eat method will be available to cat and bear objects

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