Generic tree datastructure written in JavaScript