I just want to understand how does the programm knows, that animal.prototype refers/is conected to any instanceof.bear/cat?

Tell us what’s happening:
i did the code correct, but I just want to understand how does the programm knows, that animal.prototype refers/is conected to any instanceof.bear/cat?

 i did the code correct, but I just want to understand how does the programm knows, that animal.prototype refers/is conected to any instanceof.bear/cat?

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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.44

Challenge: Use Inheritance So You Don’t Repeat Yourself

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

I just want to understand how does the programm knows, that animal.prototype refers/is conected to any instanceof.bear/cat?

when i would create a cat with the cat constructor, which dont has the function eat in it, it would still be created with the function eat, because its in Animal.prototype, but i dont understand, where does the program know it from, that Animal.prototype is a superttype for cat ?

In the code for that challenge, Bear and Cat aren’t subtypes of Animal yet. How to do that will be covered in the next two inheritance lessons.

Thanks i got it :grin: :grin: