Created
January 7, 2013 06:36
-
-
Save othiym23/4472981 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 'use strict'; | |
| function generate(parent, name) { | |
| var node = new parent.constructor(); | |
| Object.defineProperty(parent, name, { | |
| enumerable : true, | |
| configurable : false, | |
| writable : false, | |
| value : node | |
| }); | |
| return node; | |
| } | |
| function lazify(entity, axis) { | |
| Object.defineProperty(entity, axis, { | |
| configurable : true, enumerable : true, | |
| get : generate.bind(null, entity, axis) | |
| }); | |
| } | |
| function List() { | |
| lazify(this, 'next'); | |
| } | |
| function Tree() { | |
| lazify(this, 'left'); | |
| lazify(this, 'right'); | |
| } | |
| module.exports = { | |
| List : List, | |
| Tree : Tree | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment