Global functions can be accessed by their names as in:
x = function () {
alert(1);
}
window['x']();
This will execute the function. But when I have something like this:
function outer() {
var inner = function() {
}
window['inner'](); //This will not execute as inner is not global.
}
Is there any way to get around this? Application: I am trying to avoid using a switch statement where the action for each case is merely to execute a specific function based upon the value of the string. Having these functions named based upon the potential string value, entire switch statements are reduced to one statement. Example:
switch (someString) {
case 'value1' : myValue1Func();
break;
case 'value2' : myValue2Func();
break;
...
}
Can be condensed into one:
window ["my" + someString + "Func"]();
But this will only work for global functions. I do not want to make local functions global just to do this.