Skip to content

Instantly share code, notes, and snippets.

@james-gardner
Created February 20, 2014 17:06
Show Gist options
  • Save james-gardner/9118562 to your computer and use it in GitHub Desktop.
Save james-gardner/9118562 to your computer and use it in GitHub Desktop.
var Item = function (obj) {
this.children = [];
_.extend(this, obj);
};
var p = Item.prototype;
p.add = function (obj) {
this.children.push(new Item(obj));
return _.last(this.children);
};
p.each = function () {
var args = [].slice.call(arguments);
args.unshift(this.children);
return _.each.apply(_, args);
};
var root = new Item({
id : 102031,
name : 'root cause'
});
root.add({
id : 456432,
name : 'leaf'
}).add({
id : 654644,
name : 'leaf leaf'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment