Inheriting from a Class: extends keyword and Prototype Chaining
Explore how JavaScript uses prototypal inheritance with the extends keyword to create prototype chains. Understand how to traverse and modify these chains cautiously to manage object inheritance effectively.
We'll cover the following...
We'll cover the following...
extends implies prototypal inheritance
Even though JavaScript uses the extends keyword, which is popular for inheritance in Java, it’s important to remember that the inheritance is prototype-based and not class-based. Let’s verify this key design for inheritance in JavaScript with an example.
Example
We’ll continue with the Person and ReputablePerson classes we used in the previous lesson. We can obtain the prototype of an object using the Reflect.getPrototypeOf() method. Since prototypes form a chain, we ...