Accidental closures in onmouseleave/enter simulation?
I'm wondering a bit about the code which mimics onmouseleave and onmouseenter events on non-IE browsers, listed on pages 334 and 335 of the book.
For one thing, the events themselves contain quite a bit of spurious processing for the IE-browsers: all that is necessary for these guys is checking whether the code is executed by them, say by looking up e.target or so. For them the crucial final if() will always evaluate to TRUE anyway, so why bother going the extra mile.
Second, and more serious, is that I'm not entirely convinced this code is memory leak-safe. The addEventListener() calls set up explicit references from the object theDiv to itself, and unless I'm mistaken the closures in the (un)hoverElement() calls will keep all variables (target, relTarg, oTarget) alive. On a non-IE browser those might contain references to the object on which mouseover and mouseout were defined, and the result is another circular reference. (See page 125 on accidental closures for comparison.)
If I'm correct about thisâand I am really not sure I am, it is a tricky businessâthen there appears no way in which a non-IE browser can neatly simulate onmouseleave and onmouseenter events, is there?