Message from JavaScript discussions

April 2017

— Plugging algorithms into a generic traversal function


This is a clone algo:
it talks to the big daddy here:

— Since there is no recursion, this can work on very large objects

— Regular recursive methods will overflow the call stack, depending on browser

— Ah yes, a good way to implement the Strategy pattern.

— Hi, what's up?

— Well this is some weird looking code


if (iteration.done) {
return strategy(null, null, null, null, true);

— I further abstracted from the iterator protocol by providing my own strategy pattern on top of it

— Weirder albeit cool is the way this is made:

var myAlgo = new Strategy(

  (rootTuple) => {rootTuple.clone = cloneRoot},

  (tuple, accessor, exists, isObj, done) => { ... }


var result =;

Message permanent page

— Top parameter is the init function, it gets run on the root tuple of the stack, at which point any algorithm can add any objects it wants the DFS to also traverse

Message permanent page

— Bottom parameter is the main procedure which gets run per-iteration