Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23195

Re: How to detect key pressed plus mouse click, e.g., ctrl + left click

Message-ID <6801584.FWXuJcOkgI@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2014-02-22 12:50 +0100
Subject Re: How to detect key pressed plus mouse click, e.g., ctrl + left click
Newsgroups comp.lang.javascript
References (4 earlier) <LaidnWADIL12nJXOnZ2dnUVZ_i2dnZ2d@westnet.com.au> <3506285.IpskKQNfjB@PointedEars.de> <XnsA2DC7335FFCD4eejj99@194.109.133.133> <2476103.KEgCaNTNbC@PointedEars.de> <XnsA2DC768E586D7eejj99@194.109.133.133>

Show all headers | View raw


Evertjan. wrote:

> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 22 feb 2014 in
> comp.lang.javascript:
> 
>>> e || window.event
>>> 
>>> will do fine.
>>> 
>>> I [most probably] all applications,
>>> window.event will only be called if e does convert to false.
>> 
>> 1. Nothing will be *called* here.
> 
> Depending on definition, it will.

You can make up definitions all you want.  That does not change the fact 
that “window.event” is not a call, but only a property access, by the 
definitions in the language specification (and programmer’s common sense).
  
>> 2. That is beside the point; the *assignment* will take place this way
>>    even if not necessary.
> 
> Depending on definition, it will not.

Nonsense.  The statement

  e = e || window.event;

is parsed like

  e = (e || window.event);

which reads in pseudo-VM code:

  1 BOOLEAN $e
  2 NUMBER $1
  3 JNZ $2, 6
  4 ASSIGN e, $window.event
  5 RETURN $window.event
  6 ASSIGN e, $e
  7 RETURN $e

That is, *regardless* of the values of “e” and “window.event”, the 
assignment always takes place.  This is unnecessary and error-prone because 
assigning the value of “e” to “e” does usually not change the value of “e”.  
As compared to

  if (!e) e = window.event;

which reads in pseudo-VM code:

  1 BOOLEAN $e
  2 NUMBER $1
  3 JNZ $2, 5
  4 RETURN
  5 ASSIGN e, $window.event
  6 RETURN $window.event

(See the ECMAScript Language Specification, 5.1 Edition, for the elaborate 
descriptions.)
 
>> 3. If a less simple test is necessary
>> (for example, in order to prevent conversion to boolean),
> 
> Quod non.

Si tacuisses, philosophus mansisses.
 
>> the now simple expression will quickly become
>> unreadable, and hard to maintain.
> 
> That is beside the point here,
> because this is not about boolean.

Yes, partially it is.  If you use the “||” operator, the first operand will 
be converted to boolean to see if shortcut evaluation suffices.
 
The other part is the unnecessary assignment if ”e” already has the proper 
value, and error-prone if it refers to a host object (which it does).

We have been over this ad nauseam.

> e || window.event
> 
> should be so common that your mind will recognize it at once
> for the near future.

And I presume your mind is too small to store the more efficient, more 
flexible, less error-prone

  if (!e) e = window.event;
 
or better

  if (typeof e == "undefined")
  {
    e = window.event;
  }

For it is too small to realize the difference between an attribution line 
and an attribution novel already.  And an e-mail address and something that 
only resembles one.  And …

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 10:45 -0800
  Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-21 20:04 +0100
    Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 11:21 -0800
      Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-21 20:32 +0100
        Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 14:24 -0800
          Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 00:31 +0100
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 17:41 -0800
        Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Andrew Poulos <ap_prog@hotmail.com> - 2014-02-22 12:48 +1100
          Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 10:36 +0100
          Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 10:54 +0100
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 11:19 +0100
              Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 11:27 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 11:39 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 12:50 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 12:56 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click John Harris <niam@jghnorth.org.uk.invalid> - 2014-02-23 14:00 +0000
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-23 23:48 +0100
              Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-02-23 20:04 -0300
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-23 23:39 +0100

csiph-web