Development Blog

remove, remove, removeEventListener!

Ever couple of months I spend an embarrassingly long time tripping on the same stupid mistake:

win.addEventListener("pageshow", onPageShow,  true);
.. 2215 lines all twisted together...
win.removeEventListener("pageshow", onPageShow,  false);

The removeEventListener() call fails, silently, so the event handler can be called again. This symptom of the mistake can happen a long time from the error. The lines are so similar that it’s an easy mistake to make.  The dodgy documentation on Firefox events and trying to get Firebug working on FF3.1b3 provide lots of other explanations for the extra events one sees.

I really don’t get why the removeEventListener() does not give an error;  checking this would be a nice thing for a debugger to do (someday ;-).

In the mean time I’m going to try a different approach: setting the capturing value on the event handler object:

win.addEventListener("pageshow", onPageShow,  onPageShow.capturing);
.. 2215 lines all twisted together...
win.removeEventListener("pageshow", onPageShow,  onPageShow.capturing);

That way they get changed in sync. Maybe you have another way?


2 Responses to “remove, remove, removeEventListener!”

  1. Dave Sweet Says:

    The newest Firefox version does not support firebug.. FYI: a link to the version that does support it would be nice? wasting time today trying to get this back working today

  2. johnjbarton Says:

    Firebug 1.3.3 supports Firefox 3.0. Firebug 1.4 will support Firefox 3.5.