Example:
var test = 'global value';
(function() {
var test = 'local value';
// how to get the 'global value' string
})();
Given the condition that the host environment is unknown, meaning that we cannot assume that the global object will be accessible via the window name. Also, the function is not allowed to receive any arguments!
The fix
The real solution is to fix your code so your not shadowing global variables you care about.
Eval work around
You can always use global eval, it’s the most reliable.
Example
If you don’t like defining a global eval you can use
Functionto do it indirectlyLive Example
Miscellaneous hacks
The following works in non strict mode
And this hack works in broken implementations