Get JavaScript function-object from its name as a string?
Solution 1:
if you know that its a global function you can use:
var functPtr = window[func_name];
//functPtr()
Otherwise replace window with the parent object containing the function.
Solution 2:
I just did a quick test in Firebug and I was able to get the function from the name by simply eval()
ing the name... I feel dirty using eval()
, but it seems to get the job done here quite nicely.
var myFunctionPtr = eval(func_name);