Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: JavaScript Programmer's Reference
BOOK: JavaScript Programmer's Reference
This is the forum to discuss the Wrox book JavaScript Programmer's Reference by Alexei White ISBN: 978-0-470-34472-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: JavaScript Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 10th, 2010, 07:46 AM
Registered User
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7 Closures and Variables Question Mikeos BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800 2 July 28th, 2010 05:26 PM
Chapter 7 Closures and Variables Question Mikeos BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 July 21st, 2010 06:37 PM
XSLT simulation of two column Group By wholden XSLT 2 March 31st, 2008 08:57 AM
Prevent accidental update from a form donevco Access 11 January 18th, 2007 11:30 AM
Chat simulation ahardin59 ASP.NET 2.0 Basics 0 June 26th, 2006 12:22 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.