Class-based Inheritance in ES5
This lesson teaches us how class-based inheritance is implemented in the ES5 version by using constructor functions.
We'll cover the following...
Inheritance Using Constructor
Objects are inherited from the constructor function’s prototype object using the prototype chain. The same concept could also be used in the implementation of class-based inheritance, i.e., where one class inherits the properties (including methods) from another class.
There is no class keyword in the ES5 version of JavaScript; hence we use constructor functions to implement a class. Now let’s learn how class-based inheritance can be implemented using constructor functions, i.e., how one constructor function can inherit from another.
Example
Below is an example that is implementing class-based inheritance using constructor functions:
call Method
Before we get into the details of the code above, let’s discuss what a call function does.
The purpose of call is to invoke a method, defined anywhere, in the current context. Hence, this is passed as its first parameter. In the code above, call invokes the constructor method of the Shape class for Rectangle. It ...