Shanester Posted February 27, 2012 Share Posted February 27, 2012 Greetings, I would like to call a function, but the name of a function is stored in another functions argument list, like this: function chromeFix(funcName) { funcName();} The name of the function I want to call is passed to chromeFix as an argument. However, "funcName()" generates an error saying "Function expected". How can I call a function like this? PHP allows variable functions. Javascript either doesn't allow it, or I'm not doing it properly. Thanks,Shane. Link to comment Share on other sites More sharing options...
eTianbun Posted February 27, 2012 Share Posted February 27, 2012 ... Link to comment Share on other sites More sharing options...
dsonesuk Posted February 27, 2012 Share Posted February 27, 2012 function chromeFix(funcName) { alert("wait i am first"); funcName(); }var thisfunction = function hello(){alert("hello")}chromeFix(thisfunction) Link to comment Share on other sites More sharing options...
thescientist Posted February 27, 2012 Share Posted February 27, 2012 Greetings, I would like to call a function, but the name of a function is stored in another functions argument list, like this: function chromeFix(funcName) { funcName();} The name of the function I want to call is passed to chromeFix as an argument. However, "funcName()" generates an error saying "Function expected". How can I call a function like this? PHP allows variable functions. Javascript either doesn't allow it, or I'm not doing it properly. Thanks,Shane. the name isn't "stored" in the arguments, that's just how the Chromefix function knows how to reference it. the error is pretty clear though. It says it is expecting a function, as dsonesuk is showing you in his example. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2012 Share Posted February 27, 2012 It sounds like you're passing a string function name instead of a reference to the actual function. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.