1

I am learning how inheritance work in JavaScript and came across following situation.

enter image description here

If we change Ninja prototype completely with new Object then we lost the connection with old prototype. Look at the below picture.

enter image description here

Here we loose the connection with old prototype and it's old constructor function. Then how ninja instanceof Ninja assert to true? we don't have any direct connection with Ninja prototype.

Please tell me how instanceof operator find Ninja prototype on ninja object prototype chain?

4
  • attached pictures are taken from javascript for ninjas book. Commented Feb 6, 2022 at 13:42
  • 1
    DO NOT post images of code, data, error messages, etc, try How to Ask Commented Feb 6, 2022 at 14:09
  • 2
    @Naren in this case, the images come from a book which is the source of the confusion. Seems fair to use them here. Commented Feb 6, 2022 at 14:43
  • 1
    "Please tell me how instanceof operator find Ninja prototype on ninja object prototype chain?" - it doesn't. It looks for (and finds) Ninja.prototype on the prototype chain - nothing cares about the old prototype object which is not referenced by anything. Commented Feb 6, 2022 at 15:47

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.