invoke function with string javascript code example
Example: javascript execute function by string name
function executeFunctionByName(functionName, context , args ) {
var args = Array.prototype.slice.call(arguments, 2);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func].apply(context, args);
}
function myAddFunction(a,b){
return a+b;
}
var c=executeFunctionByName("myAddFunction", window, 3,4);