The prototype is based on the browser underlying the launch mechanism for ordering (not all libraries, see below). The order in which event handlers are started was not guaranteed by the original DOM events. From the DOM2 event specification :
Although all EventListeners in an EventTarget guaranteed to be triggered by any event that this EventTarget , the specification is not specified with respect to the order in which they will receive the event with respect to other EventListeners on an EventTarget .
The vast majority of browser versions (Chrome, Firefox, Opera, etc.), including IE9, run handlers in the order in which they were attached. IE8 has done the opposite before.
The newer DOM3 event specification , still in progress, introduces a requirement for them to be fired in registration order (which most browsers do):
Next, the implementation should determine the current event listeners of the target candidate. This should be a list of all event listeners registered in the current target in the order in which they are registered.
... which is probably part of why IE9 is doing it now (IE9 has noticeably improved Microsoft support for event standards by adding addEventListener , etc.).
Some JavaScript libraries (such as jQuery) guarantee ordering independent of the browser, adding only one handler for each event for each element and maintaining their own list of custom code handlers.
source share