Skip to content

Instantly share code, notes, and snippets.

@qustosh
Created February 21, 2013 18:13
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 qustosh/5006819 to your computer and use it in GitHub Desktop.
Save qustosh/5006819 to your computer and use it in GitHub Desktop.
backbone extend with super
// Extend Backbone Classes with a 'super' function to execute a method of an instance's superclass
_.each(['Collection', 'Model', 'View', 'Router'], function(className) {
Backbone[className].prototype.super = function(funcName) {
var parentPrototype = this.constructor.__super__;
if (parentPrototype && typeof parentPrototype[funcName] === 'function') {
return this.constructor.__super__[funcName].apply(this, _.rest(arguments));
}
};
});
var Account = SomeCustomCollection.extend({
initialize: function() {
this.super('initialize');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment