I'm trying to make my own eval function in JavaScript, which will execute a string in the surrounding context, like eval, plus add a few more things.
So, in general, when doing:
eval("var foo = 8");
foo; // === 8
No problem; however, when I want to extend eval
with my own function, like so:
function myEval(str) {
return eval(str);
}
myEval("var foo = 8");
foo; //error, "foo" is not defined etc.....
And the obvious reason is because in myEval, the eval function called is only executed in that function's scope, not the surrounding scope.
I was wondering if its possible to execute eval in the scope it's surrounding function was called, in order to extend the JavaScript function eval?