Skip to content

Instantly share code, notes, and snippets.

@tracend
Last active January 4, 2016 21:29
Show Gist options
  • Save tracend/8681804 to your computer and use it in GitHub Desktop.
Save tracend/8681804 to your computer and use it in GitHub Desktop.
Backbone.inherit - Combine more than one Parents in one instance #cc
(function(Backbone){
Backbone.inherit = function(){
var classes = Array.prototype.slice.call(arguments, 0);
// prerequisites
if( !classes.length ) return;
var Class = classes.pop();
// loop through objects
for( var i in classes){
var Child = classes[i];
var Parent = Class;
Class = Parent.extend( Child.prototype );
// Override the parent constructor
// Child prototype.constructor
/*
var Child = function(){
Parent.apply(this, arguments);
};
*/
}
// add local inherit
Class.prototype.inherit = inherit;
return Class;
};
// local inherit
function inherit(){
var classes = arguments;
// include this in classes (at the front)
classes = classes.unshift(this);
Backbone.inherit.apply( this, arguments );
}
})(this.Backbone);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment