Path: csiph.com!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: Ctrl + onload Date: Tue, 19 Apr 2016 19:46:52 +0200 Organization: PointedEars Software (PES) Lines: 81 Message-ID: <7166847.g7ly2KG8ZP@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1461088012 10700 eJwNysEBgDAIA8CVCBBi14HK/iPovY9RqFEWK7lckK0Iuz2vTsKo54B7s+ThMm/Z/tfHB9sf/VEQCw== (19 Apr 2016 17:46:52 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 19 Apr 2016 17:46:52 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwDAEBMCVJDwxTj32H6F3UD/OMIcbFnur9+bYGRQ5fEn0RniXqCjiWQHMcB3n9toHil6Z0NPRP3FoFf4= Cancel-Lock: sha1:diCxJT4xEkDbkDs8FvQBoRhKsrY= X-NNTP-Posting-Host: eJwNysERwDAIA7CVSsEGxilJvf8IyVcnOI0rg2BA0INlbfW2RRSTe2qSF/2/TRoJH7i7QvTmAQSEEJk= Xref: csiph.com comp.lang.javascript:30301 emf wrote: > document.getElementById("start").onclick = function (e) { > var i; > requestFullScreen(); > i = (e.ctrlKey) > ? 1 > : 0; The variable “i” is unnecessary: > init(i); init(+e.ctrlKey); works because the value of “e.ctrlKey” is of type Boolean, and the unary “+” operator converts “true” to the Number value 1, and “false” to 0. However, the type conversion, explicitly (here) or implicitly (with e.g. the “if” statement) is not strictly necessary; you could test for the Boolean value in init() instead. > }; > }; > > A couple of comments. Instead of > > textFile(0); > textFile(1); > > initially I had tried to use an for loop, which worked but JSlint found > the for unexpected, so I deduced that I shouldn't use a for loop in this > context. You should learn to understand *why* linters give you errors/warnings, and you should not blindly follow their advice. JSLint is especially notorious in giving bad/misleading advice, thanks to Douglas Crockford’s presumptions about the programming languages and the DOM that he does not understand, too. You should avoid it in favor of more sophisticated tools, like JSHint. Still, a “for” loop for two iterations resulting in two simple function calls appears to be overkill, indeed. One *can* *over*-DRY things. > Also I still have difficulty understanding why the e is now necessary in > the line: > > onclick = function (e) { ... Learn how to *ask* *questions* the *smart* way; see the FAQ. The above is _not_ a question at all; it is a statement to which my first idea was “That’s too bad.”. So such a statement is not going to help you solve your problems. I am making an exception now and answer your non-question: There is “e.ctrlKey” in the function code. “e” cannot be resolved if it is not in the scope chain, so the property access fails then. The error console tells you that: a ReferenceError exception should be thrown. See the FAQ. More, the first argument to an event listener, per the W3C DOM Level 2+ Events and Web API Specifications, is a reference to an event object, an object implementing the Event interface. It is that object that provides information as to what were the conditions when the event was fired (i.e. created and propagated to its target), including the status of the Ctrl key. Finally and *again*, your *real* name belongs in the From header field of your postings. You should not be surprised that, in addition to your posting non-questions, there are few responses if you do not show people this simple courtesy. Few people want to communicate with a three-letter entity. Internet is the thing with cables; Usenet is the thing with *people*. Again, I am making an exception here in the hope that a more direct approach works better with you, since so far you did not appear to understand the hints that you have been given in that regard. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.