Last active
January 4, 2016 21:29
-
-
Save tracend/8681804 to your computer and use it in GitHub Desktop.
Backbone.inherit - Combine more than one Parents in one instance #cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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