Message from JavaScript discussions

May 2017

— The main while loop constitutes traversal while the inner for in loop is the iteration. All the properties are iterated before traversing the next nodes

Message permanent page


So if a node has multiple child nodes like 3, they all get added to the stack in one go, then traversed in opposite order, ie discovered as 123 and traversed as 321

— I see, the algorithm part of wikipedia article is very clear

— The wikipedia one is not stack safe and its not what I coded, but its close. I used metacomposition instead of recursion

Message permanent page

— Same behavior

— Yeah, I saw

— But still, illustrates the point very clearly

— So I made a mistake typing this haha

— I havent slept for 2 weeks due to taking care of a 8 week old puppy

— Oh god

— So the main algorithm uses iterator protocol, but you can also use the Strategy interface which behaves just like an ioc callback

Message permanent page

— `var alg =
new Strategy(onFirst, onAll);
var result =;