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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.