What I learned this week about __proto__ and prototype in javaScript

First that I started to learn about inheritance in javaScript I was really confused about differance between __proto__ and prototype in JS, so I just decided to share it with you!

Well prototype is a property on the constructor function, and __proto__ is a property on constructed object which is first made from the prototype of the constructor function.

let me give an example prototype is like stamp which is made once and you use it whenever you want to print it on the paper and they’re gonna look the same as what was on stamp but there is a unique instance of that picture on stamp on paper each time and __proto__ is like an imprint which is on the paper each time .

Also you can add methods to __proto__ but actually it’s a bad way to do it because it will be also added to prototype so remember not to do so!

And also keep in mind that prototype is a property belonging only to functions.

What is prototype chaining?

Every object can have another object as its prototype. Then the former object inherits all of its prototype’s properties. An object specifies its prototype via the internal property [[Prototype]]. The chain of objects connected by the [[Prototype]] property is called the prototype chain.

Notes:

[[Prototype]]An object specifies its prototype via the internal property

__proto__ brings direct access to [[Prototype]]

prototype is the object that is used to build __proto__ when you create an object with new.

prototype is not available on the instances themselves (or other objects), but only on the constructor functions.

useful link to amazing article about this that I also used it.

thanks to dear Yan who taught me about that:)

Show your support

Clapping shows how much you appreciated saba ahmadi’s story.