Created
September 10, 2012 17:22
-
-
Save reinhrst/3692284 to your computer and use it in GitHub Desktop.
Overriding the "extend" method in backbone, also see http://stackoverflow.com/questions/12356531/how-does-one-override-the-extend-method-in-backbone/12356533
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
var enableChildTracking = function (Klass) { | |
var old_extend = Klass.extend; | |
Klass.__children = []; | |
Klass.extend = function () { | |
var That = this; | |
var result = old_extend.apply(That, arguments); | |
That.__children.push(result); | |
result.__children = []; | |
return result; | |
}; | |
}; | |
var A = Backbone.Model.extend({}); | |
enableChildTracking(A); | |
B = A.extend({}, {className: "B"}); | |
C = A.extend({}, {className: "C"}); | |
A.__children.map(function (child) {return child.className}); /* == ["B", "C"] */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment