Does javascript event handling occur inside or outside the program flow?
Posted
by
Carlo Roosen
on Stack Overflow
See other posts from Stack Overflow
or by Carlo Roosen
Published on 2012-06-01T09:59:07Z
Indexed on
2012/06/01
10:40 UTC
Read the original article
Hit count: 246
This question is related to Javascript event handling and flow control, but it is one step beyond. The question that remains unanswered is: when an event is fired and control is returned to the browser, could the browser decide to handle other events first (fired by other scripts or user action) (A), or will it always handle my event directly (B)?
The question is important, because in case (B) you can rely on the fact that nothing has been changed between firing the event and the event handler, while (A) gives no guarantees whatsoever.
My first guess is (B), how else could stopPropagation() and preventDefault() work? But giving it a second thought, it is no hard evidence.
© Stack Overflow or respective owner