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


Groups > comp.lang.javascript > #20197

Re: Alignment of three tables

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed1.swip.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <2068082.pen2y8QiGc@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Tue, 11 Jun 2013 05:09:25 +0200
User-Agent KNode/4.10.2
Content-Transfer-Encoding 8Bit
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: Alignment of three tables
Newsgroups comp.lang.javascript
References <b1jivmF20mgU1@mid.individual.net> <kp2n16$ror$1@dont-email.me> <9415734.fqrm2ecmqt@PointedEars.de> <b1m8g6Fjnc5U1@mid.individual.net> <b1mfv8Flc2aU1@mid.individual.net> <kp60kh$nrp$1@dont-email.me>
MIME-Version 1.0
Lines 79
NNTP-Posting-Date 11 Jun 2013 05:09:28 CEST
NNTP-Posting-Host a62cb857.newsspool1.arcor-online.net
X-Trace DXC=\D\0S?R:Rd7nBOkdL^Lo7>ic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@0PmZQ?n;CHJ5DZm8W4\YJN<b@mF9jNikd57a5\<`>]gf>57Y6?:M\:@1
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:20197

Show key headers only | View raw


Denis McMahon wrote:

> On Mon, 10 Jun 2013 11:16:19 -0600, Mel Smith wrote:
> 
> Given:
> 
>> pwidths = [10, 44, 23, 6, 16];
> 
> and:
> 
>>       cells[j].style.width = pwidths[j] + "%";
> 
> You're adding a number to a string.

No, they are correctly *concatenating* a primitive Number value and a 
primitive String value, which causes the former to be converted to String.

> When you try and add disparate types, the type to the right side of the +
> is usually coerced to the type to the left side of the +, if possible -
> and if it's not possible either some sort of error occurs or some
> unexpected result may be generated.

Utter nonsense.  Conversion to String (which happens when either operand is 
of type String) is *always* possible unless an object to be converted 
neither has nor inherits a toString() or valueOf() method.  There is *never* 
an error (exception) on type conversion of values of primitive types because 
those values are converted to corresponding object values (wrapper objects) 
who always have or inherit both those methods.

Whether the result of the implicit type conversion is useful, and whether 
assigning the result to a property throws an exception is another matter. 

However, *this* result *is* useful and the expression does *not* throw an 
exception.  In fact, the “width” property of “style” objects is specified 
and implemented to accept *only* (DOM)String values, so that when you assign 
a plain Number value it is likely converted to a String value (having no 
effect except in Quirks Mode or when the number is 0).

<http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties>

> It might be safer to either store the pwidths as strings:

It would *definitely* be safer for everyone if you stopped posting until you 
RTFM, RTFSpec, and got a minimum clue, as all you can post now are your 
fantasies about how the languages and APIs would be – utter nonsense.

> […]
> or use:
> 
> cells[j].style.width = "" + pwidths[j] + "%";

OMG.
 
> In the latter, addition with an empty string on the left of the + will
> coerce the number on the right to a string as it applies the addition
> left to right, and then add that string to the "%".

The algorithm for “+” makes it unnecessary to concatenate "" here; there is 
no preference in the algorithm towards left-to-right conversion.  So it 
suffices that *either* operand is of type String for concatenation *instead 
of* addition to occur:

<http://www.ecma-international.org/ecma-262/5.1/#sec-11.6.1>

That either order works is frequently a problem with beginners when they 
attempt to add a Number value to the value of an “input” element, whereas 
the latter is specified and implemented as a (DOM)String value:

<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-49531485>
<http://www.w3.org/TR/2012/CR-html5-20121217/forms.html#the-input-element>

(There are several ways how to convert a String to a Number, all explained 
in the FAQ.)

-- 
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

Alignment of three tables "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-09 08:49 -0600
  Re: Alignment of three tables Scott Sauyet <scott.sauyet@gmail.com> - 2013-06-09 08:18 -0700
  Re: Alignment of three tables Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-09 20:02 +0000
    Re: Alignment of three tables "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-09 15:01 -0600
      Re: Alignment of three tables Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-09 22:50 +0000
    Re: Alignment of three tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-10 00:46 +0200
      Re: Alignment of three tables John Harris <niam@jghnorth.org.uk.invalid> - 2013-06-10 14:41 +0100
        Re: Alignment of three tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-10 17:35 +0200
      Re: Alignment of three tables "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-10 09:08 -0600
        Re: Alignment of three tables "Mel Smith" <med_cutout_syntel@aol.com> - 2013-06-10 11:16 -0600
          Re: Alignment of three tables Denis McMahon <denismfmcmahon@gmail.com> - 2013-06-11 02:05 +0000
            Re: Alignment of three tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-11 05:09 +0200
              Re: Alignment of three tables "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-06-11 10:59 +0200
                Re: Alignment of three tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-11 16:51 +0200
              Re: Alignment of three tables Stefan Weiss <krewecherl@gmail.com> - 2013-06-14 15:38 +0200
                Re: Alignment of three tables Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-06-14 20:26 +0200
                Re: Alignment of three tables Stefan Weiss <krewecherl@gmail.com> - 2013-06-14 21:22 +0200
                Re: Alignment of three tables Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-06-15 00:36 +0200
                Re: Alignment of three tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-15 12:04 +0200
                Re: Alignment of three tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-06-15 11:41 +0200
                Re: Alignment of three tables Stefan Weiss <krewecherl@gmail.com> - 2013-06-15 13:53 +0200
                Re: Alignment of three tables Scott Sauyet <scott.sauyet@gmail.com> - 2013-06-17 04:28 -0700
  Re: Alignment of three tables "Andy" <andy@NOSPAMmanyplay.com> - 2013-06-10 09:19 +0100
  Re: Alignment of three tables Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-06-12 18:56 +0100

csiph-web