Inheritance in Constructor Functions
Explore how to implement inheritance in JavaScript constructor functions by revisiting prototypes, using the call method, and establishing prototypal chains with Object.create. This lesson helps you understand how properties and methods are shared and inherited among constructor functions and their objects.
In this lesson, we will implement inheritance on the constructor functions.
Prototypes in the constructor functions
We know that inheritance in JavaScript can be implemented through prototypal inheritance. This is when we manage to manipulate __proto__ properties of an object so it can inherit properties from other objects. Before we can move onto inheritance between constructor functions, let’s revisit the prototype property of objects created using constructor functions through the lens of inheritance.
Revisit the following example.
We know that all objects created through Employee constructor function share the same prototype property __proto__, is equivalent to Employee.prototype. All objects inherit properties from their constructor functions. The figure below outlines the phenomena.
Here, all objects share the same link to the prototypal chain. They all inherit the same properties. If we modify the prototype object, then all objects’ ...