Richard said:
You stated that:-
"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."
Right.
"due to some parser quirks they may lead to syntax errors"
Right.
"do not use the above mentioned syntax shortcut and to use full syntax
with quotes around each property name"
Right.
There is no meaning to "quotes are omitted". The names used in object
literals are one of Identifiers, string literals, or numeric literals.
String literals are not string literals without quotes and Identifiers
are not Identifiers with them.
That's pretty much points to your regular problem when dealing with
JavaScript, and on a bigger scale - the common problem of many
regulars, getting the base of their wisdom from ECMA262 3rd.ed.
ECMA262 3rd.ed. is an extremely bad source to learn the language
because its main purpose is not to explain the language, but to
describe the internal algorithms so make it possible to write
compliant engines for other than Netscape browsers. The difference is
as between say a Perl user reference and comments for C libraries used
for Perl processor.
As the result some regulars know some really refined internal
mechanics, some of which even never did into any actual
implementation, yet having troubles to get some obviousnesses. In the
particular and most importantly they are normally having big time
troubles to distinguish *language* features and *underlaying C-based
engine* features and consequently having troubles to separate properly
tokenizing, parsing and execution stages, so applying terms and
entities from one stage to another and vice versa.
Allowing Identifiers may be for simplicity (or maybe just because it
seemed like a good idea, or was so obvious that it was never questioned
and so has no motivation). There is no sense in "omitting" quotes being
"allowed" for any reason, what is allowed is a choice of tokens.
One more time, very slow: parsed by the rule of an identifier !== to
be an identifier. In object constructor all key values are string
literals, explicitly or implicitly quoted. Again, we are taking about
JavaScript, so about the execution stage. What and how exactly C
program treats the source code stream is irrelevant here yet might be
interesting in other circumstances.
The only possible trouble is that if the construct created does not
conform with the syntax rules it will result in a syntax error.
You call it "the only possible trouble"? It sounds like a joke "the
worst what may happen with you - you may die"
Indeed
As with much you write, it gets clearer as you edit more out. There is
no more talk of "syntax shortcut",
It is.
"full syntax with quotes around each
property name"
It is the full syntax because in object constructor all key values are
string literals, explicitly or implicitly quoted. Again, we are taking
about JavaScript, so about the execution stage. What and how exactly C
program treats the source code stream is irrelevant here yet might be
interesting in other circumstances.
"the quotes will be added automatically"
See right above.
"one of reserved
words in the parser list AND it changes its own previous decision"
Right, and this is one of weak points of the current parser rules. Yet
I understand that the productivity impact to accommodate this problem
may be to serious to be practical.
"it
is not a constructor but a block of statements", "consider such code as
a broken switch-case construction", etc.
Here my interpretation was wrong. "False positive" because of
"default" keyword as the troublemaker. Do not forget that the problem
was obscured by say
var obj = {class: 'foobar'}
being just fine on Gecko, so it took a really unusual combination of
factors to get an object constructor, being to lazy at the moment to
type quotes and thinking that "default" as the last key would be a
good name here.
Yet you may order some champagne to celebrate if you wich
You mean they are processed as Identifiers if they are Identifiers?
Yes they are.
No they are not. See the preface of this post. You need to learn to
distinguish the language and the underlaying engine.
If they were not Identifiers they would not be processed as Identifiers.
.... still long way to go with you... An identifier, an expression, an
object, a function are entities distinguished by their functions and
by their usage in the *language*. Can you make an effort and to get
out from the irrelevant lower level matters? It is JavaScript forum
and we are talking about JavaScript here, not about C or C++ and how
these languages are used to produce a functional JavaScript program
out of the source text.
The rest of post is the same delusion (or a trick?) to talk about
JavaScript running program, source code, C/C++ parser rules at once in
one sentence without any proper attribution of relevant parts to
relevant aspect.