Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #8424
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.kamp.net!newsfeed.kamp.net!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="UTF-8" |
| Message-ID | <1562074.40Y2kUmbCD@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Sat, 19 Nov 2011 17:09:14 +0100 |
| User-Agent | KNode/4.4.11 |
| Content-Transfer-Encoding | 8Bit |
| Subject | Re: "" + some form value |
| Newsgroups | comp.lang.javascript |
| References | <fuodc799nhk0c9ofihe817rjtkjid2cq79@4ax.com> <65Odne1L8P9dglrTnZ2dnUVZ8uydnZ2d@giganews.com> |
| Followup-To | comp.lang.javascript |
| MIME-Version | 1.0 |
| Lines | 45 |
| NNTP-Posting-Date | 19 Nov 2011 17:09:16 CET |
| NNTP-Posting-Host | d3080c26.newsspool2.arcor-online.net |
| X-Trace | DXC=e^UL[4IG@c0;]cDoEWD6A4A9EHlD;3Yc24Fo<]lROoR18kF<OcfhCO;L9HoAM`Ej_?DZm8W4\YJN<;?f@h5gMfb<<e[h?eZRZ24khIi?8n@RE8 |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.javascript:8424 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
Richard Cornford wrote: > Gene Wirchenko wrote: >> Dear JavaScripters: >> >> What does "" + some form value do? For example, >> ""+document.Contest.Last.value > > Assuming that - document.Contest.Last.value - if a reference to the - > value - property of a form element then the concatenation is actually > worthless as such - value - property values are already string > primitives. Unfortunately forced type-conversion methods often ends up > being applied as a mystical incantation, and so in contexts where they > actually have no effect. > > Incidentally, to force type conversion to a string primitive the String > constructor can be used without the - new - operator, as in:- > > String(document.Contest.Last.value) > > - Which has been both recommended against on the grounds that it could > be confused with a miss-typed - new String(s); - and recommended as a > self-documenting and explicit means of forcing type-conversion to a > string. I am leaning towards the latter. Concatenating the empty string > has been shown to be the most runtime efficient type-conversion to > string primitive operation. There is no consensus on what is most runtime-efficient here. In fact, the results at <http://jsperf.com/string-conversion-speed> vary so much between implementations, runtime environments, and even consecutive tests in the very same runtime environment, and String() is indeed self-documenting, that I am going to keep my original, ECMAScript-supported approach¹ of using String() when I do not know the type of the value and if it(s object representation) has a toString() method. PointedEars ___________ ¹) the `+' operator requires more algorithmic steps for the type conversion than String() -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
"" + some form value Gene Wirchenko <genew@ocis.net> - 2011-11-18 15:07 -0800
Re: "" + some form value "Richard Cornford" <Richard@litotes.demon.co.uk> - 2011-11-19 03:17 +0000
Re: "" + some form value Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-19 17:09 +0100
Re: "" + some form value Gene Wirchenko <genew@ocis.net> - 2011-11-20 00:07 -0800
Re: "" + some form value Dr J R Stockton <reply1146@merlyn.demon.co.uk> - 2011-11-19 18:53 +0000
csiph-web