I’ve been going over Quirksmode’s addEvent contest lately, in particular John Resig’s entry. The event listener is attached to the element with the following lines:
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
This fixes the “this” problem. But a lot of people pointed out that this will leak memory if not removed like so (when the event listener is removed, or when the page is unloaded):
delete obj['e'+type+fn];
delete obj[type+fn];
However, I tried adding the deletes, and I got an error in IE6. On further investigation, it appeared that IE6 won’t let you use the delete operator on an element node. Is there another way to free up this memory? This is the best I can do, but some comments suggested it doesn’t really stop the leaks:
obj['e'+type+fn] = obj[type+fn] = null;
Any suggestions?