Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #18982 > unrolled thread
| Started by | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| First post | 2013-03-24 11:34 +0100 |
| Last post | 2013-03-26 11:59 +0100 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.javascript
Undottability "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-24 11:34 +0100
Re: Undottability Martin Honnen <mahotrash@yahoo.de> - 2013-03-24 12:02 +0100
Re: Undottability "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-03-24 19:50 +0100
Re: Undottability Martin Honnen <mahotrash@yahoo.de> - 2013-03-26 11:59 +0100
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-03-24 11:34 +0100 |
| Subject | Undottability |
| Message-ID | <XnsA18D75C36B64eejj99@194.109.133.133> |
var a = {};
a[''] = 9;
alert(a['']); // 9
[chrome tested]
This object property seems undottable,
as you cannot write it like:
a.b = 1;
alert(a.b); // 1
Strangerder js?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-03-24 12:02 +0100 |
| Message-ID | <514edd32$0$6547$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #18982 |
Evertjan. wrote:
> var a = {};
>
> a[''] = 9;
> alert(a['']); // 9
>
> [chrome tested]
>
> This object property seems undottable,
> as you cannot write it like:
>
> a.b = 1;
> alert(a.b); // 1
>
> Strangerder js?
Well generally property names are strings and the "dot" notation only
works for those strings that are identifiers. So the general property
access notation is the "bracket" notation, not the "dot" notation.
But that is nothing new, is it? When PHP required a group of input
controls to be named 'foo[]' e.g.
<input type="radio" name="foo[]" ...>
then you always needed the bracket notation in Javascript to access
them, as in
document.forms.formName.elements['foo[]'][0]
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2013-03-24 19:50 +0100 |
| Message-ID | <XnsA18DC9DBF907Ceejj99@194.109.133.133> |
| In reply to | #18983 |
Martin Honnen wrote on 24 mrt 2013 in comp.lang.javascript:
> Evertjan. wrote:
>> var a = {};
>>
>> a[''] = 9;
>> alert(a['']); // 9
>>
>> [chrome tested]
>>
>> This object property seems undottable,
>> as you cannot write it like:
>>
>> a.b = 1;
>> alert(a.b); // 1
>>
>> Strangerder js?
>
> Well generally property names are strings and the "dot" notation only
> works for those strings that are identifiers. So the general property
> access notation is the "bracket" notation, not the "dot" notation.
Okay.
So they are always strings, even the empty string,
and a number is converted to a string first?
var a = {};
a['8'] = 2;
a[08] = 9;
alert(a['8']); // 9
alert(a[8]); // 9
a['08'] = 2;
alert(a[8]); // 9
a['8'] = 1;
alert(a[8]); // 1
alert(a.length); // undefined [not an array]
> But that is nothing new, is it? When PHP required a group of input
> controls to be named 'foo[]' e.g.
> <input type="radio" name="foo[]" ...>
Well, I don't speak php,
why would it require that in this example?
> then you always needed the bracket notation in Javascript to access
> them, as in
> document.forms.formName.elements['foo[]'][0]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-03-26 11:59 +0100 |
| Message-ID | <51517faa$0$6552$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #18987 |
Evertjan. wrote: > So they are always strings, even the empty string, > and a number is converted to a string first? Yes, see http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.1, the expression in square brackets is evaluated first and then the result of the evaluation is converted to a string. >> But that is nothing new, is it? When PHP required a group of input >> controls to be named 'foo[]' e.g. >> <input type="radio" name="foo[]" ...> > > Well, I don't speak php, > why would it require that in this example? I think for PHP server-side code to handle a group of input element values (like a group of checkboxes or radio buttons) as an array the naming convention "groupName[]" with the suffix "[]" is required.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web