From: Dr J R Stockton on
In comp.lang.javascript message <Xns9D91A337DCE2Feejj99(a)194.109.133.242>
, Tue, 8 Jun 2010 14:02:42, Evertjan. <exjxw.hannivoort(a)interxnl.net>
posted:

>In essence I still have no idea what an 'object-litteral' is.

It is a spelling mistake.

In the present sense, a literal is a part of [ECMAScript] source code.
That source code is not of itself an [ECMAScript] string, but it can be
handled as a string by any language that can be given an appropriate
reference to it.

A literal is a representation of a value which can be assigned in the
language to something that things can be assigned to : it might be
termed an assignand by analogy with operand - it is a possible value
argument for an assignment operator, in the same way that an expression
is.

A literal uses in itself no operators and no external identifiers. The
literal {a:1, b:2, c:3} uses no identifiers, but introduces three; and
{a:1, b:a, c:b} introduces three identifiers & uses two of them - it is
probably a literal, but it is not a valid ECMAScript literal, according
to Firefox.

An example of a Number Literal is 4; 2+2 is not a literal, but it is an
expression equivalent to that Literal.

An Object Literal is one which defines an Object value; a Boolean
Literal (there are two) defines a Boolean value; etc.



ECMA 262 (rightly) does not define a literal in general; it probably
describes all/most possible types of ECMAScript literal except an Object
Literal.


See also <http://en.wikipedia.org/wiki/Literal_(computer_science)>.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: John G Harris on
On Thu, 10 Jun 2010 at 10:20:36, in comp.lang.javascript, Dr J R
Stockton wrote:

<snip>
>ECMA 262 (rightly) does not define a literal in general; it probably
>describes all/most possible types of ECMAScript literal except an Object
>Literal.

Note that, in spite of its name, an ObjectLiteral is not a literal but,
as ECMA 262 says,

"a form resembling a literal".

In particular, it can produce a different value each time it's executed,
as in

{ a: new Date() }

John
--
John Harris
From: John G Harris on
On Thu, 10 Jun 2010 at 10:20:36, in comp.lang.javascript, Dr J R
Stockton wrote:

<snip>
>The
>literal {a:1, b:2, c:3} uses no identifiers, but introduces three; and
>{a:1, b:a, c:b} introduces three identifiers & uses two of them - it is
>probably a literal, but it is not a valid ECMAScript literal, according
>to Firefox.
<snip>

The error is to be expected as the a in b:a is a global variable
that presumably has not been created. Things would be even more
confusing if it had been created.

A related case is

var v = { a:13, b:19 };
v = { a:42, b:v.a };
alert(v.b);

which displays 13 as v is not assigned the new object until it has
been fully built.

The moral of these two examples is
Don't Do That!
in real code.

John
--
John Harris
From: Dr J R Stockton on
In comp.lang.javascript message <vQ5b6MGW77EMFw$5(a)J.A830F0FF37FB96852AD0
8924D9443D28E23ED5CD>, Sat, 12 Jun 2010 18:07:34, John G Harris
<john(a)nospam.demon.co.uk> posted:

>On Thu, 10 Jun 2010 at 10:20:36, in comp.lang.javascript, Dr J R
>Stockton wrote:
>
> <snip>
>>The
>>literal {a:1, b:2, c:3} uses no identifiers, but introduces three; and
>>{a:1, b:a, c:b} introduces three identifiers & uses two of them - it is
>>probably a literal, but it is not a valid ECMAScript literal, according
>>to Firefox.
> <snip>
>
>The error is to be expected as the a in b:a is a global variable
>that presumably has not been created. Things would be even more
>confusing if it had been created.

In ECMAScript, yes. But in another language it could be a literal where
the second a was a reference to the preceding a which has a value of 1.

Likewise, 'aa''bb' is a perfectly good literal (I just ran a
program using it), though not in ECMAScript, where one would write
"aa'bb" or 'aa\'bb' .


Aside : who can suggest, without testing, what Safari
4.0.5 will give for (1/65536).toString(16) ?

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)