Skip to content

Instantly share code, notes, and snippets.

@jhonsore
Last active September 2, 2016 14:30
Show Gist options
  • Save jhonsore/78f4de4143a4edad9851 to your computer and use it in GitHub Desktop.
Save jhonsore/78f4de4143a4edad9851 to your computer and use it in GitHub Desktop.
String to function in javascript
// 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