Jump to content

chaining functions with eval


alexnofue

Recommended Posts

Hi, i've been 'chaining' functions with eval, it seems to work okay except for one detail, i'm not so sure if the first function it's on hold waiting for a second to finish.for example

function one(){    ...    eval('two()');    ...}function two(){    ...    alert('hello');}

my problem with this is that the two() migth have holding one() for as long as the user closes the alert, so it's not nice if the first one is an ajax or something.or it's there a workaround for this?

Link to comment
Share on other sites

Hi, thanks JSG for your reply, if it works that way i better be very careful with the 'chaining', i'm doing this because i'm sending the name of the function as a parameter to a function that pick it and put it in the eval.To be more specific i put together a function for the ajax requests that i might need so i call it every time i need ajax, so it works similar to this:function goajaxgo(url, param, ... , 'function_name()'){ ... ... ... //when the request is finished eval('function_name()');}so i'm sending a lot of function names to the same function, if you want i could post the whole code but i don't consider it adds much.greetings.

Link to comment
Share on other sites

I use JSG's technique when posting AJAX data. It looks a little like this:

function post_data (data, callback, mode) {   // stuff   AJAX.onreadystatechange = callback;   // stuff}

It makes the function very reusable, which I guess is what you are after.

Link to comment
Share on other sites

Hi, well i change the eval for the JSG's code suggestion and it worked just as i expected to, meaning that after the change everything keep working plus the new code makes sure it's a function.I'll try to keep this 'chaining' to the minimun and the chained functions short and simple.thanks for your replies JSG and DD.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...