Last active
September 2, 2016 14:30
-
-
Save jhonsore/78f4de4143a4edad9851 to your computer and use it in GitHub Desktop.
String to function in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function name and parameters to pass | |
var fnstring = "customFunc"; | |
var fnparams = [1, 2, 3]; | |
// find object | |
var fn = window[fnstring]; | |
// is object a function? | |
if (typeof fn === "function") fn.apply(null, fnparams); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment