settimeout - Stopping Nested Timeouts in Javascript -


i want execute piece of arbitrary code , able stop whenever want. figured settimeout , use cleartimeout stop it. if code in timeout creates it's own timeouts, keep executing after clear original.

example:

var timeoutid = settimeout(     function(){         console.log("first event can stopped cleartimout(timeoutid)");         settimeout(function(){console.log("but not one")}, 5000)     }, 5000) 

now 1 way control code being executed , make store value of additional timeouts global variable , clear them @ once. there better way this? , there way on arbitrary code?

to clarify, i'm trying able execute function want, stop whenever want, if function contains timeouts

you can put inner timeout variable too:

var innertimeout,     timeoutid = settimeout(     function(){         console.log("first event can stopped cleartimout(timeoutid)");         innertimeout = settimeout(function(){console.log("but not one")}, 5000);     }, 5000); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -