Does anyone remember the addEvent recoding content a few years ago? I found myself looking at it today and decided to write an entry. The contest closed almost 6 years ago, so I can't exactly enter, but it was still a fun thing to consider.
The original rules for entry stated that the result had to work in IE5. That's right, IE five. This was a fascinating condition because IE5 doesn't support a lot of the things I tend to rely on. For example, it doesn't know:
Since my first attempt used them I had to find work-arounds, which is why my solution is 250 lines long. I think it covers all the bases though. It fixes memory leaks of any event added using this library, it keeps its global variable flooding down to a minimum (1) and it can handle capturing. It doesn't fit the classic addEvent(element, event, function) syntax, but can be easily modified. It can also be expanded to include support for browsers that understand neither addEventListener nor attachEvent... just incase...
It's worth me pointing out that this isn't a critique of any of the other entries or the overall winner. A lot of the stuff that I do in this library is based on knowledge gained by those who entered this competition.
Still, this was a fun way to spend an afternoon. My complete piece of code can be found on my website and is yours for the taking.
The original rules for entry stated that the result had to work in IE5. That's right, IE five. This was a fascinating condition because IE5 doesn't support a lot of the things I tend to rely on. For example, it doesn't know:
- Function.call and Function.apply
- Array.shift
- Array.push
Since my first attempt used them I had to find work-arounds, which is why my solution is 250 lines long. I think it covers all the bases though. It fixes memory leaks of any event added using this library, it keeps its global variable flooding down to a minimum (1) and it can handle capturing. It doesn't fit the classic addEvent(element, event, function) syntax, but can be easily modified. It can also be expanded to include support for browsers that understand neither addEventListener nor attachEvent... just incase...
It's worth me pointing out that this isn't a critique of any of the other entries or the overall winner. A lot of the stuff that I do in this library is based on knowledge gained by those who entered this competition.
Still, this was a fun way to spend an afternoon. My complete piece of code can be found on my website and is yours for the taking.
Help













