Last Updated: February 25, 2016
·
629
· bnquoctoan

Call javascript function from string name

var strFunc = "myFunc";
var strParam = "functionParameter"

//Create the function
var func = window[strFunc];

//Call the function
func(strParam);

3 Responses
Add your response

Maybe elaborate what's going on here? maybe a less cryptic example?

over 1 year ago ·

Why would you even do that?

over 1 year ago ·

We can use it in case we need to dynamically call function.

over 1 year ago ·