Last Updated: February 25, 2016
·
837
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#javascript
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside