Summary of the addEvent contest discussion

This is my attempt at summarizing the discussion following the announcement of the addEvent recode contest winner on

On October 18 Peter-Paul Koch announced John Resig's entry to be the winner of the addEvent recoding contest. Immediately after there was quite some discussion about this entry (and it's problems) and a general concensus that this script may just not be cut out for it's job.

The identified problems with John Resig's script (although it was the most brief and to-the-point entry) are following (note that not all of these were actual requirements):

PPK than posted an interesting remark in comment #32:

As far as I can see the most important remaining issue is how to look up events that have already been attached, either to remove them or to prevent duplicate attachments.

He overlooked the fact that some entries already did just that, but this suggestion was actually quite on the mark:

What we'd really need is some sort of hashtable to look up attached events, with some sort of unique key that is not the function body.

That finally is exactly what Dean Edwards solved (in a - imho - briljant way) in his version.

After that some more discussion followed surrounding a.o. Dean's code, mainly between some participants that had actually submitted scripts that were conceptionally simular to Dean's version (in particular me and Angus Turnbull). This discussion was mainly aimed to see how we could combine all the good points of our and Dean's scripts and improve on it. At this moment I have already made some changes/improvements to Dean's script and summarized what I feel could still be improved on

I think we're at a point where the direction is laid; Dean has provided us with a good solution in a compact script and now it's only a matter of finetuning (meanwhile Dean has already posted an updated version with some nice enhancements).

The following point is also worth mentioning: execution order is actually irrelevant (although I first thought it was important); in both the W3C's and Microsoft's event model the execution order is explicitly undefined so addEvent doesn't need to define it (but maybe we should mention this for novice users).