Implementing inheritance in classes

Earlier in this chapter, we saw how difficult it was to implement inheritance hierarchies in functions. Therefore, ES6 aims to make it easy by introducing the extends clause and the super keyword for classes.

By using the extends clause, a class can inherit static and non-static properties from another constructor (which may or may not be defined using a class).

The super keyword is used in two ways:

  • It's used in a class constructor method to call the parent constructor
  • When used inside the methods of a class, it references the static and non-static methods of the parent constructor

Here is an example to demonstrate how to implement an inheritance hierarchy in constructors using the extends clause, and ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.