tree-traversal.js
function traverseRecursiveSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

  (function visitNode(node) {
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++) {
      visitNode(subnodes[i]);
    }
    options.onNode(node, options.userdata);
  })(rootNode);

  return rootNode;
}
function traverseRecursiveSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

  (function visitNode(node) {
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++) {
      visitNode(subnodes[i]);
    }
    options.onNode(node, options.userdata);
  })(rootNode);

  return rootNode;
}
function traverseRecursiveSync ( rootNode , options ) { options = extend ( { subnodesAccessor : function ( node ) { return node . subnodes ; } , onNode : function ( node , userdata ) { } , userdata : null } , options ) ; ( function visitNode ( node ) { var subnodes = options . subnodesAccessor ( node ) ; for ( var i = 0 ; i < subnodes . length ; i ++ ) { visitNode ( subnodes [ i ] ) ; } options . onNode ( node , options . userdata ) ; } ) ( rootNode ) ; return rootNode ; }
Synchronously traverses the tree recursively.
Synchronously traverses the tree recursively .