Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to execute a JavaScript function when I have its name as a string
// see also
window.example = function () { alert('hello world'); };
name = 'example';
window[name] = function () { alert('hello world'); };
window[name] = new Function( 'alert("hello world")' );
//and finally call the function
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.