Jump to content

Running a function by variable value...


ajlisowski

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/201543-running-a-function-by-variable-value/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.