Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3506285.IpskKQNfjB@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 22 Feb 2014 10:54:43 +0100 User-Agent: KNode/4.11.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 54 NNTP-Posting-Date: 22 Feb 2014 10:54:53 CET NNTP-Posting-Host: 38f6e1ab.newsspool1.arcor-online.net X-Trace: DXC=I0YFM[B8bW@E4ZB2flKORAic==]BZ:afN4Fo<]lROoRAnkgeX?EC@@@JMNQ;63YamDDZm8W4\YJNLYUVHKH;GI^G>8ZdD_1a;VHYXOSXaJibDM X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:23191 Andrew Poulos wrote: > On 22/02/2014 6:32 AM, Evertjan. wrote: >> document.onmousedown = function(e) { >> var e = e || window.event; >> if (e.shiftKey || e.altKey || e.ctrlKey) >> alert ( "shiftKey=" + e.shiftKey + "\naltKey=" >> + e.altKey + "\nctrlKey=" + e.ctrlKey ); >> }; > > I notice that you put a "var" before the "e". Is that really necessary? No. As ā€œeā€ is in the formal parameter list, it is treated as as if it was a local variable. Redeclaring a local variable has no effect. Initializing it like that also has not. A local variable can come in handy if the original value of the argument of the function call is needed later. The local variable SHOULD have a different identifier then (otherwise it would prevent accesses to the argument value by parameter name). Only insofar development tools (like Eclipse JSDT) that warn about parameter assignment are useful here, because ECMAScript implementations support only call-by-value (references to objects are values; properties and variables cannot be referenced in terms of their memory locations): Accidental assignments to the parameter itself will not change a value in the calling execution contexts. > With > > > var e = "1"; > > function foo(e) { > window.alert(e); > } > > foo("2"); > > > wouldn't the alert display "2"? No, it would. However, the whole operation is bogus. It should be at least if (!e) e = window.event; so that the assignment only takes place when necessary. Further feature tests are recommended, see jsx.dom.createEventListener() [1]. [1] -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.