js call function by string name
function test() {
console.log('Executed function "test".');
}
window['test']();
js call function by string name
function test() {
console.log('Executed function "test".');
}
window['test']();
javascript execute function by string name
//function to execute some other function by it's 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);
}
//my adding function, could be any function
function myAddFunction(a,b){
return a+b;
}
//execute myAddFunction from string
var c=executeFunctionByName("myAddFunction", window, 3,4); //7
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us