I'm trying to access a variable local to a function in an external function as a free variable.
This is what I'm trying to achieve:
function try_evaluate() {
var i = 0;
show_r("i <= 10");
}
function show_r(expression) {
if (eval(expression)) {
i++;
show_r(expression);
} else alert(eval(expression));
}
I get an error because the variable i
is not defined in the scope of show_r
. Making i
a global variable works but I need i
to be a local variable.