Understand the Prototype Chain

Understand the Prototype Chain
0.0 0

#1

Hi campers, in object oriented programming (OOP) challenges ,FCC explains what is prototype and every thing about it ,and untill now what I know is that when you don’t want to repeat properties that are common between a lot of objects and that they will just be repeated for no sense ,you add it to the prototype Object constructor that is inside the function constructor like this ,

function Dog (name){
this.name=name;
}
Dog.prototype.numLegs=4; // here every object instance will inherit this property .
let  dogOne= new Dog("linda");

my question is about the prototype has another prototype because it is an object ,this is called prototype chain . but when we want to access the second prototype we access it like this :

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

typeof Bird.prototype; // => object

Object.prototype.isPrototypeOf(Bird.prototype); //why here we access it by Object.prototype
// returns true

why we can not access it like this :
Bird.prototype.prototype without using Object.
and thank you in advance.


#2

You’re missing a link in the chain. The prototype has a constructor property. That points back to the function that created the object. That has a prototype property. It’s not prototype.prototype.


#3

so now the second prototype is an object and also named Object?


#4

Yes (more specifically the name of the constructor for the object that the prototype is a property of) :slightly_smiling_face: . In this case the constructor of the second one in the chain is Object (as the constructor for first is Bird).

First one is Bird. Bird inherits from Object. Object inherits from null. null inherits from nothing, it’s the top of the chain


#5

thank you for your time ,the practise will improve my skill.