![]() | |
#31
| |||
| |||
|
|
Consider this example: *function a() { * *var a = {a: 42}; * *return a.a; *} The identifier "a" is used five times, three times to name the function, the variable and the object property, and two times to reference the variable and the object property. |
|
In the case: *var a = "foo"; *function() { * *var a = "bar"; *} would you expect the variable inside the function to be called "foo"? |
|
It's called "a" too, because a name *in a declaration* is not interpreted.. It's the same for object initializers: They contain declarations of properties. The names are not interpreted, so: *var a = "foo"; *var b = {a : 42}; declares a property named "a" on an object, not "foo". |
#32
| |||
| |||
|
|
"VK's universe": because object property name is a string one may skip quotes as they are implied. But in this case it has to conform with JavaScript naming rules for identifiers because the parser is optimized for the quickest code source parsing so it will not bother with each and every non-quoted literal context: it just checks that each non-quoted literal is either a number, or one of reserved values like true or null, or a valid JavaScript variable name. If neither it drops the parsing so do no waste the time. |
#33
| |||
| |||
|
|
VK wrote: Richard Cornford wrote: For the Fx (ab)normality I am going to ask out of curiosity at mozilla.dev.tech.js-engine Richard Cornford wrote: On your record of such promises, I will not be holding my breath. http://groups.google.com/group/mozilla.dev.tech.js-engine/msg/cb7669ddd693937a |
#34
| |||
| |||
|
#35
| |||
| |||
|
|
var obj = { a: "a", default: "b" } the "interpretation decision" is being made before entering so it is already decided that it is an object constructor and not a block of statements, so it is irrelevant that the first key is not quoted: the quotes will be added automatically; THEN the system meets [default] chars sequence which corresponds to one of reserved words in the parser list AND it changes its own previous decision: now no, it is not a constructor but a block of statements with the second one preceded by an illegal label literal. Some might find it very logical. I am definitely not in that club. snip |
#36
| |||
| |||
|
|
To be the most precise about the weird VK's universe which is can/must be considered totally twisted yet is immutable by design: |
|
[...] I seem to understand - after a few beers - that implicitly quoted foo in var obj = {foo : 'bar'} may be also interpreted as an identifier that doesn't identify anything. |
|
After one more beer [...] |
#37
| |||
| |||
|
|
here! *`foo' is called an identifier because it must be produced by the /Identifier/ production. |
#38
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: here! `foo' is called an identifier because it must be produced by the /Identifier/ production. Almost perfect, one half in there already! |
|
It is no way an identifier, it is a string *parsed by the rules of an identifier* |
|
[more VK nonsense] |
#39
| ||||
| ||||
|
|
`foo' is called an identifier because it must be produced by the /Identifier/ production. |
|
Almost perfect, one half in there already! |
|
You must be kidding. |
|
VK wrote: Having a statement such as: var obj = { foo: 'bar', default: 'default_value' } Firefox 3.5.3 creates obj with properties foo and default. IE reports syntax error "Expected identifier, string or number", same or similar syntax error occurs on Safari, Chrome and Opera. By placing default into quotes we are making the code valid for all browsers in question: var obj = { foo: 'bar', 'default': 'default_value' } 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). IE has yet to ship the ES5 JScript implementation I've seen demo'ed at Ecma TC39 meetings. |
#40
| |||
| |||
|
|
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. [...] |
![]() |
| Thread Tools | |
| Display Modes | |
| |