Skip to content

Instantly share code, notes, and snippets.

@reinhrst
Created September 10, 2012 17:22
Show Gist options
  • Save reinhrst/3692284 to your computer and use it in GitHub Desktop.
Save reinhrst/3692284 to your computer and use it in GitHub Desktop.
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