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


Groups > comp.lang.javascript > #8433

Re: "" + some form value

From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.javascript
Subject Re: "" + some form value
Date 2011-11-20 00:07 -0800
Organization A noiseless patient Spider
Message-ID <64dhc7h1es0b15ocbap2l7akkpc85kso7s@4ax.com> (permalink)
References <fuodc799nhk0c9ofihe817rjtkjid2cq79@4ax.com> <65Odne1L8P9dglrTnZ2dnUVZ8uydnZ2d@giganews.com>

Show all headers | View raw


On Sat, 19 Nov 2011 03:17:21 -0000, "Richard Cornford"
<Richard@litotes.demon.co.uk> wrote:

>Gene Wirchenko wrote:

[snip]

>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 

     I think I will, too.

>has been shown to be the most runtime efficient type-conversion to 
>string primitive operation.
>
>> Won't document.Contest.Last.value be string regardless?
>
>Yep.
>
>> I tried forcing one such to a number,
>
>How? Strings can be type-converted into number primitive values using, 
>say,  +string  or  Number(string)  (and commonly in the past or 
>string*1 , or  string-0 ).

     With an assignment statement.  The following statement was an
alert() to get the typeof() and reported string.

[snip]

>>     Is this ""+ a bit of superstition, or am I missing something?
>
>No, it appears to be superstition in this case. Though there is a slight 
>possibility that - document.Contest.Last - was not referring to a form 
>element in this case (then you only have evidence of poor code design 
>rather than a mystical incantation).

     No, definitely a form element.  That is why I was puzzled about
it.

Sincerely,

Gene Wirchenko

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


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