Possible Duplicate:
Javascript multiple inheritance
Is there a way in JavaScript to do this:
Foo = function() {
};
Bar = function() {
};
Baz = function() {
Foo.call(this);
Bar.call(this);
};
Baz.prototype = Object.create(Foo.prototype, Bar.prototype);
var b = new Baz();
console.log(b);
console.log(b instanceof Foo);
console.log(b instanceof Bar);
console.log(b instanceof Baz);
So that Baz is both an instance of Foo and Bar?
JavaScript does not have multiple inheritance.
instanceoftests the chain of prototypes, which is linear. You can have mixins, though, which is basically what you’re doing withFoo.call(this); Bar.call(this). But it is not inheritance; inObject.create, the second parameter only gives properties to copy, and is not a parent.