"prototype" is called "a reference to another object". From where? From any javascript object.
So, prototype is a parent from your custom object.
If none parent is set, then the parent is the object "Object".
And this parent points to primitive type "null".
const b = { b: 1 }
b // the custom object
b.__proto__ // the parent "Object"
b.__proto__.__proto__ // null
__proto__ gets an object prototype from the object itself!
Just it. Here we have what is called "prototype chain".
But, be careful, as we said before, every object point to the same parent "Object".
const custom1 = {c1:1}
const custom2 = {c2:2}
custom1.__proto__.myNewProp = 2
console.log(custom2.myNewProp) // prints: 2
Good luck! ;)
Top comments (0)