Skip to content

Instantly share code, notes, and snippets.

@Comandeer
Created July 6, 2015 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Comandeer/52b82c5e74e2ce5c73c7 to your computer and use it in GitHub Desktop.
Save Comandeer/52b82c5e74e2ce5c73c7 to your computer and use it in GitHub Desktop.
Multi inheritance in JS
var A = function()
{
}
,B = function()
{
}
,C = function()
{
}
,createProto = function()
{
var protos = [].slice.call(arguments)
,prototype = {};
protos.forEach(function(proto)
{
Object.keys(proto).forEach(function(key)
{
prototype[key] = proto[key];
});
});
return prototype;
};
A.prototype = {
constructor: A
,metoda1: function() {}
,metoda2: function() {}
};
B.prototype = {
constructor: B
,metoda3: function() {}
,metoda4: function() {}
};
C.prototype = createProto(A.prototype, B.prototype);
var c = new C();
console.log(c instanceof A, c instanceof B, c instanceof C);
C.prototype = new B();
c = new C();
console.log(c instanceof B, c instanceof C);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment