I am trying to define a function that can access variables that are in the scope of the function that calls it.
(I'm trying to create a string formatter that is prettier than "a" + b, and shorter than String.format ("a {0}", b). So I can get SF ("a {b}" ), and I do not know if this is possible)
So
function magic (str) {
return parentScope [str]; // or return eval (str);
// or something like that
}
function call () {
var a = 1;
alert (magic ("a"));
}
call ();
will warn "1".
I can currently do this if the function return code should be evaluated, but it seems like there should be a better way.