Constructor-Based Classes
Let’s learn about subtyping with constructor-based classes.
We'll cover the following
Subtyping with constructor-based classes
Before the version ES2015, JavaScript didn’t have an explicit class concept. Subtyping was also not directly supported, so it had to be implemented with the help of certain code patterns that provide two inheritance mechanisms: (1) inheritance of properties and (2) inheritance of methods.
Classes can be defined in two alternative ways: constructor-based and factory-based. Both approaches implement inheritance in their own way.
The following example helps summarize the ES2015 code pattern for defining a superclass and a subclass in a constructor-based single-inheritance class hierarchy:
Get hands-on with 1400+ tech skills courses.