DEV Community

Bruno Moura
Bruno Moura

Posted on

[Javascript] - [Part 1] - Prototype

"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
Enter fullscreen mode Exit fullscreen mode

__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
Enter fullscreen mode Exit fullscreen mode

Good luck! ;)

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay