Created
February 21, 2013 18:13
-
-
Save qustosh/5006819 to your computer and use it in GitHub Desktop.
backbone extend with super
This file contains 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
// 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