I am trying to define a function which can access variables which are in the scope of the function that is calling it.
( I am attempting to build a string formatter that is prettier than "a" + b, and more terse than String.format("a{0}",b). So I can get SF("a{b}"), and I don't know if it 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();
would alert "1".
currently I can do this by having the function return code to be eval'd, but it seems like there must be a better way.