Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Easy multiple-inheritance in Backbone.js
(function () {
function extendEach () {
var args = Array.prototype.slice.call(arguments),
child = this;
_.each(args, function (proto) {
child = child.extend(proto);
});
return child;
}
Backbone.Model.extendEach =
Backbone.Collection.extendEach =
Backbone.Router.extendEach =
Backbone.View.extendEach = extendEach;
})();
@hughes

This comment has been minimized.

Copy link

@hughes hughes commented Feb 21, 2013

Clever little script. If I'm not mistaken, you'd use it like ClassC = Backbone.Model.extendEach(ClassA, ClassB, [properties])

@sroze

This comment has been minimized.

Copy link

@sroze sroze commented Jun 11, 2013

Nop, use like that (see the .prototype):

var MyModel = Backbone.Model.extendEach(Another.Model.prototype, ..., [properties])
@robinduckett

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment