Question

if I have

$("a#foo").click();
$("a#bar").click();
dostuff();

and both have click handlers attached which do different things..is it guaranteed that bar's click handler will only execute after foo's completes? or are they dispatched asyncronously

similarly..will dostuff() only execute after foo and bar's click handlers complete?

Was it helpful?

Solution

The Javascript execution model in the browser is single threaded (by and large), so there is no asynchronous dispatch going on anywhere outside stuff like the HttpXmlRequest.

So the foo click() function will return before bar click() is called, which will return before doStuff() is called.

OTHER TIPS

It depends on what foo does (You could technically set up foo to fire events using setTimeout which could fire after the method completes), but yes bar should fire after foo completes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top