I have an issue where I have recursion inside of a for loop:
function func(node) {
for(var i = 0; i < node.children.length; i++) {
func(node.children[i]);
}
}
Obviously because JavaScript does not have block scope, the same i variable is getting modified each time the function is called. What is the best way to remedy this? Assume regular EcmaScript 3 and I can't use JavaScript 1.7 "let".
I know this has been asked before, but the other questions don't seem to show recursion, they show one function call where a closure could be used.