ajlisowski Posted May 12, 2010 Share Posted May 12, 2010 Hey all, lets say I have a variable that contains a function name. How can I call that function without using eval? More specifically, I have created a grid jquery object. I want to use this on multiple pages to display different data. Depending on the page I want to have certain actions do different things. So right now I pass in an option containing the name of the function I want to call. I then have a function within the jqeury object that runs when the action occurs that evals that option. I dont want to use eval. How do I do this another way? Quote Link to comment https://forums.phpfreaks.com/topic/201543-running-a-function-by-variable-value/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 There are 'variable functions'. Have you looked at the php manual? Quote Link to comment https://forums.phpfreaks.com/topic/201543-running-a-function-by-variable-value/#findComment-1057375 Share on other sites More sharing options...
ajlisowski Posted May 12, 2010 Author Share Posted May 12, 2010 Im confused...I am not using PHP. Lets say I have an jquery object that has a function submit. I want that function to be able to use a variable to call another function. $obj.submit=function (callfunc){ eval(callfunc+'();'); } this would call the given function. I want to do so better, where perhaps I pass the function itself and not a string containing the function name. And I dont use eval. Quote Link to comment https://forums.phpfreaks.com/topic/201543-running-a-function-by-variable-value/#findComment-1057386 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2010 Share Posted May 12, 2010 Oops. I did not notice that you were not using php... Quote Link to comment https://forums.phpfreaks.com/topic/201543-running-a-function-by-variable-value/#findComment-1057391 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.