The prototypal mechanism of inheritance leads us to the conclusion that JavaScript supports single inheritance. In fact, since an object has just one prototype link and we can assign just one prototype object to a constructor function, we can conclude that an object can inherit features from just one other object. However, the flexibility of JavaScript allow us to implement multiple inheritance in a simple way.
But what is multiple inheritance? It is the ability to inherit features from more than one object or class at the same time. Suppose, for example, that we have two constructors or classes: Developer
and Student
. We want to be able to create objects that represent developers who study, that is, objects that inherit features both from the Developer
and Student
. Multiple inheritance allows us to compose features deriving from more than one object or class into a new type of object. Let's explain how to implement it in JavaScript.
We start from our Developer...