1function test() {
2 console.log('Executed function "test".');
3}
4
5window['test']();
1//function to execute some other function by it's string name
2function executeFunctionByName(functionName, context , args ) {
3 var args = Array.prototype.slice.call(arguments, 2);
4 var namespaces = functionName.split(".");
5 var func = namespaces.pop();
6 for(var i = 0; i < namespaces.length; i++) {
7 context = context[namespaces[i]];
8 }
9 return context[func].apply(context, args);
10}
11
12//my adding function, could be any function
13function myAddFunction(a,b){
14 return a+b;
15}
16
17//execute myAddFunction from string
18var c=executeFunctionByName("myAddFunction", window, 3,4); //7