Prototypical Inheritance in Javascript

Ashraful Islam
The Startup
Published in
4 min readSep 2, 2020

--

In Javascript we don’t have classes, rather we only have objects. So if we want to implement inheritance with objects we can get the help of prototypical inheritance.

Before talking about prototypical inheritance, we all should stay on the same pitch in terms of javascript prototype. So,

Prototype in Javascript

Suppose we have one object john . We have another object person .

john is a type of person , right?

We will add the common behaviors to the person object, then later somehow we will link this person object with the john object. Now we can refer person as the prototype of john object.

Prototype is just a parent of another object.

Every object in javascript (except a single one) has a prototype object. Now the question is how this prototype looks like?

We can get the help of the Chrome dev tool to see how a prototype looks like.

In the above screenshot, we can see the prototype of person object inside __proto__ property. Yes, this is the prototype of person

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.