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


Groups > comp.lang.javascript > #32142

Re: How bad is my hack?

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: How bad is my hack?
Date 2017-01-08 23:39 +0100
Organization PointedEars Software (PES)
Message-ID <5139801.MhkbZ0Pkbq@PointedEars.de> (permalink)
References <hack-20170108182735@ram.dialup.fu-berlin.de>

Show all headers | View raw


Stefan Ram wrote:

> event => alert( event.cancelable, event.preventDefault() )
> 
>   Explanation: I want to show the value of »event.cancelable«,
>   and prevent the default handling for the event, but was too
>   lazy to open a block and write
> 
> event => { alert( event.cancelable ); event.preventDefault(); }
> 
>   . Actually, I did not want the line to become too long.
> 
>   How bad is this hack?
> 
>   [ ] Why, we all do it this way!
> 
>   [ ] In the next version of webappapis.html#dom-alert, »alert«
>       will get a second parameter, and your code will break!

<diddle>
>   [x] The maintenance programmer will not understand your
>       intentions.
</diddle>

Also, in some implementations the alert() method *does* have a meaningful 
second argument; IIRC it specified the title of the alert window when there 
still was one (nowadays, popup messages are more common).
 
>   Well, now that I see the block, I observe that it is not
>   that much longer, so I just might change my code to the
>   version with the block.

Please do.  And always write “window.alert(…)” instead of “alert(…)”.

That said, avoid “…alert(…)” for developers in favor of “console.…(…);”.
“…alert(…)” is a nuisance and can easily get a PITA if used wrong because it 
removes the focus from the window.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

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


Thread

Re: How bad is my hack? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-08 23:39 +0100

csiph-web