Use Inheritance So You Don't Repeat Yourself I don't understand

Tell us what’s happening:
I don’t understand the whole “new prototype” thing. What I mean is how Javascript knows that the new parent prototype(Animal) is connected to the two prototypes(Cat and Bear)

I just don’t understand it. Can anyone please explain this to me?

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; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-inheritance-so-you-dont-repeat-yourself

The next lesson in the series will ask you to connect them, keep going…

I keep going but I don’t know which one way I’m supposed to connect them. Is it by using the property constructor? I’m confused and it’s night right now so I’m all confused and sleepy and stuff lol so excuse me for anything dumb…

just keep going, it is multi-step topic

I mean. I’m about to finish the section already and I’m still confused about the way to connect them…

If you have 7 minutes, watch this explanation of why and how to create two objects that inherit from the one object.

2 Likes

Ok, thank you a lot!