Call javascript function from string name
var strFunc = "myFunc";
var strParam = "functionParameter"
//Create the function
var func = window[strFunc];
//Call the function
func(strParam);Written by Quoc Toan
Related protips
3 Responses
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
Best
#Javascript
Authors
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#