Event listeners in javascript?

Edit: Well, since I don't know why you don't want it to know about the continuation, here's another suggestion with the exact same semantics but maybe a desirable syntax, now there is a simulation of event delegation anyway :) (thing is, you need the Inc function to somehow report completion).

Edit: Well, since I don't know why you don't want it to know about the continuation, here's another suggestion with the exact same semantics but maybe a desirable syntax, now there is a simulation of event delegation anyway :) (thing is, you need the Inc function to somehow report completion): function Inc(val1,val2){ var handle = { oncomplete: null }; var intervalID = setInterval(function(){ if (val1 > val2) { clearInterval(intervalID); if (handle. Oncomplete) handle.oncomplete(); } val1 = val1 + 10; }, 400); return handle; } Inc(10, 40). Oncomplete = function(){ alert("Finish"); }; Previous: Something like this should to the trick (I did not test it though): function Inc(val1,val2, continuation){ var intervalID = setInterval(function(){ if (val1 > val2) { clearInterval(intervalID); if (continuation) continuation(); } val1 = val1 + 10; }, 400); } Then call it like this: Inc(x, y, function(){ Inc(y, z); }).

But in this case Inc "knows" about the second Inc (though it anonymous but still knows) I don't want that. – luppi Feb 3 '10 at 23:21 I added a new suggestion but now, you have to return a handle so not a great solution. – Ekin Koc Feb 3 '10 at 23:55 yes, this will work.

Thanks – luppi Feb 4 '10 at 8:46.

I usually try to stay away from timeouts, especially if they deal with something that requires recursion. But why do you need recursion if the function is only executed twice? // call Inc the first time Inc(); // this will execute only after the first Inc(); is done.

// call Inc the second time after X seconds setTimeout(Inc, 400).

Inc foo is for animation (it has more code of course), so I need setinterval – luppi Feb 4 '10 at 8:01 I run Inc first time to animate element in one direction and then, after x seconds I use same inc to animate object in another direction – luppi Feb 4 '10 at 8:48.

AFAIK there is no type of standarized custom-eventing, but you are making the work-around. Calling a "delegate" this way: var myFunction = function() { // CALL Inc with different params, this is your "event" }; function Inc(val1, val2) { setInterval(myFunction,400); } Short answer, not for custom events (only DOM-standard events), but you can fake it.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions