I am using debouncing to execute events after a timeout using settimeout. The problem I have, is that other javascript events expect those events to occur synchronously. Since they are now executing after a timeout, I’d like to be able to trigger them prematurely by other javascript events (so those events requiring them won’t fail).
Anywhom, if I do something like:
timeout = setTimeout(function() { alert('hi'); }, 10000);
, and I want that to occur before 10 seconds passes, how can I do that?
The solution can involve jquery if necessary. Thanks!
Edit:
Is it possible to do this with just access to the timeout object?
So, if you make whatever you’re delaying its own function:
You can use a timeout and a regular function call:
Or to call it before the timeout expires, just call the function whenever you need to:
Am I on the right track here? If you need to cancel the timeout, call
clearTimeout()on yourtimeoutvariable.