xmultiple
Multiple inheritance with ES6 proxies.
Provides multiple inheritance in the same manner as JavaScript's native inheritance mechanism, by delegating to other objects. But rather than delegating to just one other object, as the prototype chain does, this library creates a proxy that will delegate to multiple other objects.
Installation
$ npm install --save xmultiple
Usage
var xmultiple = ; // Object inherits from multiple other objects const base1 = 'foo': 'foo'; const base2 = 'bar': 'bar'; const base3 = 'baz': 'baz'; const delegatesToMultiple = ; delegatesToMultiplefoo // "foo" delegatesToMultiplebar // "bar" delegatesToMultiplebaz // "baz" // Class inherits from multiple other classes { return 'foo'; } { return 'bar'; } { return 'baz'; } Base1 Base2 Base3 const delegatesToMultiple = ; delegatesToMultiple // "foo" delegatesToMultiple // "bar" delegatesToMultiple // "baz"
Notes
- Ambiguous calls (that is, collisions) will throw an error.
{} {} Base1 Base2 const delegatesToMultiple = ;delegatesToMultiple // error! ambiguous, Base1#foo or Base2#foo?
-
It's slow. It's a couple orders of magnitude slower than either
Object.assign
or subclass factories. I hope it will get faster over time. -
Calling super constructors is problematic. Calling
super()
will invoke only the singular home object, but neither can the proxy iteratively invoke each super constructor since class constructors can't be function-called.
Alternative
If this library doesn't meet your needs, instead consider subclass factories.
const Base1 = {};const Base2 = {};const Base3 = {}; {}
License
MIT © Jeff Mott