Javascript – Get JavaScript function-object from its name as a string


In JavaScript, if I have a string in a variable, is there a way to get a reference to the function object which has that matching name? Note that jQuery is available to me so I can use any of its helper methods also.

For example:

myFunction = function(){};

var func_name = "myFunction";
var myFunctionPtr = ???  //how to get the function from the name


Best Solution

if you know that its a global function you can use:

var functPtr = window[func_name];

Otherwise replace window with the parent object containing the function.