Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Event target in browsers Date: Sat, 31 May 2014 00:07:25 +0200 Organization: PointedEars Software (PES) Lines: 102 Message-ID: <38956158.OWfjujO1v6@PointedEars.de> References: <69413$5387765f$6def49ce$18425@nntpswitch.blueworldhosting.com> <5294499.JCWY7Ix9cy@PointedEars.de> <5388cc48$0$6672$9b4e6d93@newsspool3.arcor-online.net> <28ef9$5388d14c$6def49ce$30712@nntpswitch.blueworldhosting.com> <5437208.zU8Ddvy3tv@PointedEars.de> <5388ea24$0$6669$9b4e6d93@newsspool3.arcor-online.net> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1401487648 17755 eJwFwQkRADAIAzBL9AYtyGEP/iUsiUXwyBn0mJi8h6bdWspJjtt1FErcJQNeLJ/O7PsOBP8OcxCE (30 May 2014 22:07:28 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 30 May 2014 22:07:28 +0000 (UTC) User-Agent: KNode/4.12.4 X-User-ID: eJwNxsEBwCAIA8CV0EAq46CS/Ueo97oAB8/nDHoolMSgA1rHFtMOq7e0Skj0FKZX0Q2Z5i+qHd2zX4L3nh9CuRXL Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Thomas 'PointedEars' Lahn wrote: >> Cezary Tomczyk wrote: >>> 2014-05-30 20:22, Christoph Michael Becker wrote: >>>> >>>> for details and >>>> >>>> for a workaround that may be viable. >>> >>> I see there: >>> >>> "One solution to emulate the event.currentTarget feature is to wrap your >>> handler in a function calling the handler using Function.prototype.call >>> with the element as a first argument. This way, this will be the >>> expected value." >>> >>> I'll take a look at it more closely. >> >> Whereas “this” is formatted with a fixed-width font, which is important. >> >> Anyhow, I can save you some time here: >> >> Note that this argument is based on the assumption that either “this” >> would always refer to the object that the event handles or that circular >> references involving host objects would not be a problem in non-W3C-DOM >> implementations. AISB, the former lacks specification or at the very >> least >> some serious testing at this point. The latter has been shown to be >> false: the FAQ has a long section on the IE Memory Leak issue. > > As I understand the MDN article, they suggest something like: > > el.attachEvent("onclick", function () { > (function () { > // handle the event > }).call(el); > }); > > If I'm not mistaken, this should work as expected (i.e. with "this" > bound to "el"). And it would create a circular reference involving a host object. > Regarding the memory leak issue: where is this section in the FAQ? I > was not able to find it on the start page, nor does it seem to be listed > in the notes' TOC. It can be found under “Javascript Closures” for now both in the original FAQ and the “FAQ for comp.lang.javascript”. The issue arises because closures are created accidentally, and this creates a circular reference. See below. > Thanks to your comment in JSX:dom/events.js, I found PPK's article, but > it is rather old (2005?), and the issue might have been fixed for later > MSHTML versions. The point of PPK’s article (which is not entirely correct either, see the comments) is to avoid addEvent(), a wrapper devised at that time that used attachEvent() as fallback for addEventListener(). Since both methods work differently, that is demonstrated not to be a viable approach. *That* issue was certainly fixed insofar as that Microsoft has finally deprecated attachEvent() in favor of the W3C DOM API as of IE/MSHTML 9.0, and removed as of IE/MSHTML 11.0. DOM Level 0 has “this”, and the W3C DOM provides the “currentTarget” event property, which both make referring to the handling object by context-external identifier unnecessary. Googling for “dom events circular reference”, I have found in which it is assumed that the memory leak issue has been resolved in IE 8 at least for circular references involving DOM objects. Since “The Archive Gallery has been retired.” I have found the abstract of the referred whitepaper in the Internet Archive: In this blog there never has been an update on this. As the link to MSDN in the whitepaper was dead, too, this lead me to search MSDN Library, where I finally found using “events circular reference” as keywords. It also links to a more detailed explanation of the problem. In short, Microsoft states there that they have resolved the memory leak issue for DOM host objects as of Internet Explorer 8 by treating them like native JScript objects. If anyone has done some serious testing on this, I am looking forward to updating the corresponding section of the “FAQ Notes” in the “FAQ for comp.lang.javascript”. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.