Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16838
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="ISO-8859-1" |
| Message-ID | <3335047.320Uf1SXUN@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Wed, 24 Oct 2012 21:57:02 +0200 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 7Bit |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: Programming style question |
| Newsgroups | comp.lang.javascript |
| References | <timstreater-13F0F1.22343820102012@news.individual.net> <cP4vbFDDoChQFwQo@invalid.uk.co.demon.merlyn.invalid> <timstreater-89CF41.09503722102012@news.individual.net> <iuja88hvfo1fs4ai8giqe79d0p7g1b1hq9@4ax.com> <s4sa889g1978stjqgqhg5esjpnk7oqeqgj@4ax.com> <pPCdncn5wICZDhjNnZ2dnUVZ_uednZ2d@earthlink.com> <tucb88te23lg15laq5a0meriminejqeko1@4ax.com> <XnsA0F578505BA8Eeejj99@194.109.133.133> <f5td88dckgks06mf02cssn9e0116qum6c8@4ax.com> <XnsA0F5E78026978eejj99@194.109.133.133> <722e889us0ep0mra233907giq2nnolqhge@4ax.com> <XnsA0F6619B1C3Ceejj99@194.109.133.133> <k69fb6$530$1@news.albasani.net> |
| Followup-To | comp.lang.javascript |
| MIME-Version | 1.0 |
| Lines | 90 |
| NNTP-Posting-Date | 24 Oct 2012 21:57:02 CEST |
| NNTP-Posting-Host | a115b9cb.newsspool3.arcor-online.net |
| X-Trace | DXC=;4Sm?OSe_?X<<0iRN7DLEQMcF=Q^Z^V3X4Fo<]lROoRQ8kF<OcfhCO[o;k`8g]<bOWDZm8W4\YJN\J`:FmdeL>KP40i@2K255T[N=i01>COLQQ |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:16838 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
Stefan Weiss wrote:
> On 2012-10-24 09:35, Evertjan. wrote:
>>>> Asking what OTHER languages have the same syntax as Javascript?
>>>>
>>>> This surely is off topic in this NG,
>>>> as it does not even help understanding Javascript.
>
> I strongly disagree with that statement. Comparing JavaScript to other
> languages is very much on topic in this group. If you're not interested
> in those discussions, feel free to skip them.
ACK.
>> Oh sorry, perhaps you don't like this
>> BECAUSE you cannot do this in some other language,
>> where you would desperately need multiline if-else-then constructs.
>
> Just because you can write cryptic code in JS doesn't mean you have go
> out of your way to do it.
ACK.
> Talking about cryptic code, the || operator in Perl works in a similar
> way. There's even some syntactic sugar for assigning default values to
> variables:
> $foo = $foo || 42;
> can be shortened to
> $foo ||= 42;
There is also
$foo = 42 if not defined $foo;
and similar in Perl, which is probably slightly more efficient [no
assignment if $foo is not defined()/whatever].
> But enough about other languages, I don't want to bore you with these
> "off topic" comparisons. Here are some better examples for where the
> value returned by the || operator can be used in JS:
>
> // simple default values
> var textColor = opts.color || userPrefs.color || "black";
There is a real use-case for that.
> // DOM0 event handler
> document.onclick = function (evt) {
> var e = evt || window.event;
> ...
> };
This is error-prone if `evt' refers to a host object, and unnecessarily
inefficient. And document.onclick?
> // initialize a "namespace" object without overwriting it
> var myLib = myLib || {};
This is unnecessarily complicated. An `if' statement will do better and
will be slightly more efficient.
> myLib.myFunc = function () { ... };
>
> // call a method on an optional argument
> function findParagraphs (parentEle) {
> return (parentEle || document).getElementsByTagName("p");
> }
This can be error-prone. In particular, there is a problem when expression
in the `||' operation is a reference to a Function instance. Some functions
can only be called as methods of an (specific) object.
> // combining && and ||
> function textOfFirst (parentEle, eleName) {
> var ele = parentEle.getElementsByTagName(eleName)[0];
> return ele && ele.firstChild && ele.firstChild.data || "";
> }
This is error-prone as the return type would vary (one of Null, Element or
descendant, Text, or String) depending on runtime conditions that one has
virtually no control over. (In fact, the first line is error-prone already
as null has no properties). To be avoided.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-18 08:32 +0100
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-18 10:23 +0200
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-18 13:42 +0100
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-18 17:59 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-18 09:56 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-19 00:49 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-19 11:04 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-20 11:52 +0200
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-19 12:06 -0700
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-10-19 23:12 +0100
Re: Programming style question "Mel Smith" <med_cutout_syntel@aol.com> - 2012-10-19 21:56 -0600
Re: Programming style question Bart Van der Donck <bart@nijlen.com> - 2012-10-20 02:21 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-20 12:03 +0200
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-20 06:31 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-20 18:30 +0200
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-20 10:32 -0700
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-10-20 22:34 +0100
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-21 10:12 +0200
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-10-21 09:34 +0100
Re: Programming style question Dr J R Stockton <reply1242@merlyn.demon.co.uk.invalid> - 2012-10-21 17:59 +0100
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-22 09:55 +0200
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-10-22 09:50 +0100
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-22 04:49 -0700
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-10-22 14:04 +0100
Re: Programming style question Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-10-22 16:07 +0200
Re: Programming style question Dr J R Stockton <reply1243@merlyn.demon.co.uk.invalid> - 2012-10-23 18:22 +0100
Re: Programming style question Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-10-22 16:01 +0200
Re: Programming style question Jim T. <x@y.z> - 2012-10-22 12:16 -0400
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-22 11:40 -0700
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-22 14:01 -0700
Re: Programming style question Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-10-23 10:07 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-23 09:43 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-23 11:49 +0200
Re: Programming style question Jim T. <x@y.z> - 2012-10-23 15:52 -0400
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-23 13:07 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-23 22:45 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-23 14:14 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-24 09:35 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-24 10:17 -0700
Re: Programming style question Dr J R Stockton <reply1243@merlyn.demon.co.uk.invalid> - 2012-10-25 18:41 +0100
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-25 17:03 -0700
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-25 20:14 -0700
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-25 20:46 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-26 09:55 +0200
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-26 06:18 -0700
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-26 17:43 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-26 09:57 -0700
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-26 10:24 -0700
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-26 14:18 -0700
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-27 10:45 +0200
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-27 12:58 +0200
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-27 16:18 +0200
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-27 18:08 +0200
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-27 18:26 +0200
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-27 19:43 +0200
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-27 21:09 +0200
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-27 22:53 +0200
Re: Programming style question John G Harris <john@nospam.demon.co.uk> - 2012-10-28 11:37 +0000
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 12:50 +0100
Re: Programming style question Martin Leese <please@see.Web.for.e-mail.INVALID> - 2012-10-28 13:43 -0600
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-28 23:58 +0100
Re: Programming style question John G Harris <john@nospam.demon.co.uk> - 2012-10-29 11:18 +0000
Re: Programming style question Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-10-27 23:58 +0200
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 12:43 +0100
Re: Programming style question Dr J R Stockton <reply1243@merlyn.demon.co.uk.invalid> - 2012-10-27 19:44 +0100
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-24 12:06 -0700
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 21:27 +0200
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-10-24 15:12 -0700
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-10-25 01:29 +0100
Re: Programming style question Stefan Weiss <krewecherl@gmail.com> - 2012-10-24 21:25 +0200
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 21:57 +0200
Re: Programming style question Stefan Weiss <krewecherl@gmail.com> - 2012-10-25 01:11 +0200
Re: Programming style question Christoph Becker <cmbecker69@gmx.de> - 2012-10-25 02:00 +0200
Re: Programming style question Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-24 20:27 -0700
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-25 08:44 +0200
Re: Programming style question Adam Silver <adambsilver@gmail.com> - 2012-10-25 04:28 -0700
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-25 23:18 +0200
Re: Programming style question Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-26 08:24 -0700
Re: Programming style question Stefan Weiss <krewecherl@gmail.com> - 2012-11-07 22:13 +0100
Re: Programming style question Tim Streater <timstreater@greenbee.net> - 2012-11-07 21:51 +0000
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-07 23:47 +0100
Re: Programming style question Stefan Weiss <krewecherl@gmail.com> - 2012-11-08 01:14 +0100
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-11-07 16:51 -0800
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-08 16:45 +0100
Re: Programming style question Scott Sauyet <scott.sauyet@gmail.com> - 2012-11-08 08:02 -0800
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-08 17:39 +0100
Re: Programming style question Gene Wirchenko <genew@ocis.net> - 2012-11-08 11:25 -0800
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-08 22:25 +0100
Re: Programming style question John G Harris <john@nospam.demon.co.uk> - 2012-11-09 10:19 +0000
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-09 17:41 +0100
Re: Programming style question Dr J R Stockton <reply1245@merlyn.demon.co.uk.invalid> - 2012-11-10 22:38 +0000
Re: Programming style question Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-22 12:32 -0700
Re: Programming style question Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-10-23 10:05 +0200
Re: Programming style question Christoph Becker <cmbecker69@gmx.de> - 2012-10-22 22:11 +0200
Re: Programming style question Stefan Weiss <krewecherl@gmail.com> - 2012-10-23 02:42 +0200
Re: Programming style question Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-10-23 10:08 +0200
Re: Programming style question "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-10-20 18:34 +0200
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-18 11:57 +0200
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-18 13:06 +0100
Re: Programming style question "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-18 15:32 +0300
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-18 13:37 +0100
Re: Programming style question "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-18 15:55 +0300
Re: Programming style question John G Harris <john@nospam.demon.co.uk> - 2012-10-19 10:12 +0100
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-19 07:24 -0700
Re: Programming style question John G Harris <john@nospam.demon.co.uk> - 2012-10-20 17:47 +0100
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 01:15 +0100
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 01:31 +0100
Re: Programming style question "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-24 07:34 +0300
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 19:57 +0200
Re: Programming style question "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-10-24 21:02 +0300
Re: Programming style question Patricia Shanahan <pats@acm.org> - 2012-10-18 20:15 -0700
Re: Programming style question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 01:21 +0100
Re: Programming style question Scott Sauyet <scott.sauyet@gmail.com> - 2012-10-21 17:57 -0700
csiph-web