Extending an object with a tree-traversing method in javascript -


i have custom object contains array (called "children") objects of same type stored, in result creating tree.
let's looks that:

function customobject(){     if (this instanceof topic) {     this.text = "test";     this.children = [];     } else         return new customobject(); } 

now, add "forall" method object execute function provided argument, on elements of tree in depth-first fashion. what's best way it?

something this?

customobject.prototype.forall = function(func) {   // process object first   func(this);    // process children   (var = 0; < this.children.length; i++)     this.children[i].forall(func); } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -