2

In JavaScript we are allowed to set the multiple listeners on the single event. For example:

element.addEventListener('click',startDragDrop,false);
element.addEventListener('click',spyOnUser,false);

I am planning to do the same in my project. I just want to be sure that it should not cause any problem with the order of the execution of the callback the way it is written on QuirksMode. It says that W3C model does not state which event handler is fired first, so you cannot assume startDragDrop() is executed before spyOnUser(). But I want to be sure that my startDragDrop should be executed first then spyOnUser(). Is there any way I can make it sure?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Hitesh Kumar
  • 3,508
  • 7
  • 40
  • 71
  • Yes, that's why it's called *add*EventListener and not *set*EventListener. – Loïc Faure-Lacroix Feb 15 '16 at 05:28
  • http://stackoverflow.com/a/25016769/1984039 – gurvinder372 Feb 15 '16 at 05:28
  • As per the previous comment's link, order is guaranteed by the newer spec. But if you want to support really old browsers you'd have to use your own event binding proxy to control order, or use a library (e.g. jQuery guarantees this even for old browsers that don't support addEventListener). – nnnnnn Feb 15 '16 at 05:35
  • Thanks I need to not be worried about older browsers cause we are not supporting them..:) – Hitesh Kumar Feb 15 '16 at 05:37

0 Answers0