Software Development

Inheritance in Object-oriented JavaScript

Inheritance in JavaScript is called prototypal inheritance. Objects inherit from objects. When we create an object from a class,

[wp_ad_camp_5]

it always inherits from

In Java speak, this is like saying  “any class inherits from Object class”.

If we point MyClass.prototype to another object, e.g., new Person(), MyClass objects now inherit from Person object.

[wp_ad_camp_4]

Outputs:

[wp_ad_camp_3]

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like