Skip to content

Instantly share code, notes, and snippets.

@othiym23
Created January 7, 2013 06:36
Show Gist options
  • Select an option

  • Save othiym23/4472981 to your computer and use it in GitHub Desktop.

Select an option

Save othiym23/4472981 to your computer and use it in GitHub Desktop.
'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