Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to execute a JavaScript function when I have its name as a string
// see also https://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string
window.example = function () { alert('hello world'); };
//or
name = 'example';
window[name] = function () { alert('hello world'); };
//or
window[name] = new Function( 'alert("hello world")' );
//and finally call the function
example();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.