Created
February 20, 2014 17:06
-
-
Save james-gardner/9118562 to your computer and use it in GitHub Desktop.
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 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