Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: eventDispath how that work Date: Wed, 15 Oct 2014 15:24:48 +0200 Organization: PointedEars Software (PES) Lines: 52 Message-ID: <1791221.7QuZn8ShVB@PointedEars.de> References: <16yzpmtikrwk0$.1schjt968gcx$.dlg@40tude.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 1413379489 2304 eJwNysERwDAIA7CVAGNcxml7sP8IyVsiyutXFiu53Mfn7c0QxuCh7k9WGoUT8Pt8J7u5VldwAPqtD5A= (15 Oct 2014 13:24:49 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Wed, 15 Oct 2014 13:24:49 +0000 (UTC) User-Agent: KNode/4.14.1 X-User-ID: eJwNzMERACEIBLCWUGCRcjhW+i/hnPzjioUOg8N8nsRG5Nzywly9iIhjG8v6hJYzJSnk0oOWT6qbRO1XUBM/P5wVHQ== Cancel-Lock: sha1:TJ5rHUnxwdXHO6MdIdTXkxmQ3As= X-NNTP-Posting-Host: eJwNxkkBwCAMBEBLTfeAyKEJ+JdA5zWCwzVomTo6Ofmx3Agx5fV0bzon3h5aofgnopLY7OQFA/IP9A== Xref: csiph.com comp.lang.javascript:25911 JJ wrote: > On Tue, 14 Oct 2014 16:23:39 +0200, Une Bévue wrote: >> function sendTest(e) { >> console.log("sendTest(e) e:"); >> console.dir(e); >> event = new CustomEvent('build', { 'detail': e.target.dataset.date >> }); e.target.dispatchEvent(event); You need to write var event = …; or you could accidentally access (and perhaps overwrite) the built-in “event” property of the Window object of the global execution context, which likely is in the scope chain. > e = document.querySelector("#elem"); Avoid this newer, less compatible, less efficient pattern, and replace it with e = document.getElementById("elem"); You also need to declare “e”. Otherwise – often discussed here before – the code will not run in strict mode and will cause side-effects in non-strict mode: var e; Declaration and initialization can be combined: var e = document.getElementById("elem"); (Likewise, when you are tempted to write document.querySelector(".foo") then write document.getElementsByClassName("foo") instead. [Of course, you still need to make sure that Document::getElementsByClassName() is implemented. Usually you would use a wrapper method instead that falls back to an implementation of Document::getElementsByTagName("*").]) -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.