Inheritance in JavaScript using Prototype

Hi Friends,

In this section, we are going to discuss Inheritance in Javascript. Inheritance is one of the OOPs methodology. But, here we will implementing the same in JavaScript.

Therefore, in the above snippet, I have simply created one simple Parent Class and Child class with one properties and methods to it. Also note that both these two methods takes one dynamic argument and get returned with some concatenated expression, fairly simple. Now, we need to make child class inherit parent class properties using Prototype property.

Now, when I run the same in browser, it will return true in both the cases as shown below.

9th

10th

This means now I have access to both Child class and Base class properties’ and methods’. Now, let us go ahead and access the instance’s methods and properties.

With the above change, it will display the following Result:-

11th 12th

We can also gain access to properties as well.

13th

14th

Also, we can override the base class method with child class method as shown below in the snippet.

15th

With this, I would like to wrap this session. I Hope you would have enjoyed the same.

Thanks,
Rahul Sahay