ES6 Multiple Inheritance

Leo Cavalcante
1 min readFeb 21, 2015

--

Multiple inheritance was often something that leads to the old know diamond problem. This problem was “solved” by Java/C# using the Interfaces, classes that do no implement, this is used in PHP too.

I highly recommend that you have a look at: ‘Interface’ Considered Harmful by Robert C. Martin (Uncle Bob). That was the post that inspired me to search something releated to JavaScript.

Alternate methods to have some sort of Multiple Inheritance includes Traits and Mixins. Traits was implements in PHP 5.4, as documentation says:

A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

In JavaScript, specifically the React (the apple of God’s eye), we can use Mixins when create a new class. In fact, is such a great pattern to archive Multiple Inheritance. So I made this kind of example on how you can reach this using ES6 and npm’s mixin library.

Leave some comments!

--

--