![]() | |
#41
| |||
| |||
|
|
////////////////////// // explanation starts Object constructor property names are always treated as string literals, so quotes around them may be omitted in the source code to speed up typing and/or for a better code readability. |
#42
| ||||||||||||
| ||||||||||||
|
|
Thomas 'PointedEars' Lahn wrote: `foo' is called an identifier because it must be produced by the /Identifier/ production. VK wrote: Almost perfect, one half in there already! Thomas 'PointedEars' Lahn wrote: You must be kidding. Deadly serious. You just keep thinking over it - the main part of the path is already done. btw somehow I overlooked the answer of Brendan Eich to my post at mozilla.dev.tech.js-engine Who doesn't have this group and doesn't want to use GG I am copying it here: VK wrote: snip My question is if it is a Gecko bug, a convenience extension or the proper implementation by ECMA with others being wrong on that? Brendan Eich wrote: Not a bug, yes a convenience, and proper implementation of ES5 (after ES3.1 and ES4, which both allowed reserved words to be used in property-name contexts). Also a proper extension to ES3, which allows such syntactic extensions (see chapter 16). snip So it is as as earlier explained: property names are strings, explicitly quoted or implicitly quoted. |
|
PropertyName : IdentifierName StringLiteral NumericLiteral |
|
Brendan Eich refers to ECMA 262 3rd.ed. Chapter 16 "Errors" http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf and logically I do agree with him: if a non-quoted character sequence in this position is guaranteed to be quoted (treated as a string literal on the execution stage) |
|
then it is really not a parser's monkey business to check its language naming conformance or check it against a reserved words table. Any way coming back to the same: ////////////////////// // explanation starts Object constructor |
|
property names are always treated as string literals, |
|
so quotes around them may be omitted in the source code |
|
to speed up typing and/or for a better code readability. |
|
The drawback of such syntactical shortcut is that then all property names have to obey the JavaScript naming rules |
|
and not be equal to any of JavaScript reserved words: otherwise due to some parser quirks |
|
they may lead to syntax errors. This way it is highly suggested do not use the above mentioned syntax shortcut |
|
and to use full syntax |
|
with quotes around each property name. var obj = { foo : 'bar' // no doughnuts! } var obj = { 'foo' : 'bar'// good boy! } |
#43
| |||
| |||
|
|
To show, once again, that it's not just a matter of omitting quotes, consider this object initializer: *var obj = { "3.0" : 42, 3.0 : 37 }; Guess what is alerted by: * alert([obj[3], obj[3.0], obj["3"], obj["3.0"]]); (It's "37,37,37,42", if there was any doubt) |
#44
| |||
| |||
|
#45
| ||||||
| ||||||
|
|
Lasse Reichstein Nielsen wrote: To show, once again, that it's not just a matter of omitting quotes, consider this object initializer: var obj = { "3.0" : 42, 3.0 : 37 }; Guess what is alerted by: alert([obj[3], obj[3.0], obj["3"], obj["3.0"]]); (It's "37,37,37,42", if there was any doubt) I am not forcing anyone to "my universe", just explaining why am I comfortable in there. |
|
If one decides to make the interpreter dizzy |
|
or to conduct a "sh** check" |
|
on it rather than writing reliable programs |
|
than ECMA's Book of Source (Chapter 6) |
|
provide a lot of "useful" hints: [...] |
#46
| |||||||||||||
| |||||||||||||
|
|
Did you hear about http://en.wikipedia.org/wiki/G%C3%B6del%27s_incompleteness_theorems#First_incom pleteness_theorem |
|
? IMHO you are trying to make in this little topic the same what Dr. is trying with calendars: prove it wrong by having built both consistent and complete description of something. |
|
I don't - |
|
plus I definitely know that there are not any identifiers in here, |
|
I like the semantics too much to let them into. |
|
My explanation remains unchanged. |
|
Maybe(?) it is not complete |
|
but it is consistent for any sane practical use. |
|
At the beginning I also though to add "to syntax errors or to unforeseen results" with var obj = { 300000000000000000003 : 0, 3000000000000000000003 : 0 }; |
|
but rightly didn't do it because it may give an idea that such coding can be met somewhere or even possible while the task is to lock such path for thinking completely. |
|
"syntax error" sounds short and serious, verbosed explanations of possible problems spoil the effect. |
|
It's just like "don't go on the red or may be killed". There is no need to spell all possible vehicles causing the death and all possible deadly options. ![]() |
|
////////////////////// // explanation starts snip: Nothign worth seeing here. // explanation ends ////////////////////// |
#47
| |||
| |||
|
|
Thomas 'PointedEars' Lahn" wrote: Richard Cornford wrote: There is no need to propose any automatic insertion of quotes into the source text (or token stream) in order to account for the behaviour seen. And indeed such insertions would be contrary to the behaviour observed. For example:- var x = { * * x-y:5 }; - is a syntax error but:- var x = { * *'x-y':5 }; - is not. The first being a mathematical expression in a context that only allows for Identifiers, string literals and numeric literals, while the second is a numeric literal. * * * * * * * * * * * * * * * * *^^^^^^^ Do you mean "string"? Yes I did. As for the rest, thank you for your patient explanations. *One can only hope something of it gets through to him. Pigs may fly. *;-) |
#48
| |||
| |||
|
|
As you know, I consider that mental illness on your part is the theory that best fits the evidence of your actions. Interesting that you say so. |
#49
| |||
| |||
|
|
"Richard Cornford" wrote: Thomas 'PointedEars' Lahn" wrote: As for the rest, thank you for your patient explanations. One can only hope something of it gets through to him. Pigs may fly. ;-) While your wisdom is no doubt lost on VK, it is greatly appreciated by others who learn by reading your responses. If you were to collate your posts to clj for a book along the lines of Crockford's Good Parts, I'm sure it would quickly become a best seller. |
#50
| |||
| |||
|
|
No, your postings so far range only from being a nuisance to an annoyance; they must be incredibly confusing to newcomers. *That is probably the only reason why I do not have you killfiled yet: Someone has to deal with your naive, foolish presumptuousness, disprove your fairytale stories, correct your outright lies; in short: someone has to put you in your place. |
![]() |
| Thread Tools | |
| Display Modes | |
| |