On the syntax edge

A

Alexis Nikichine

I have mistakenly left in my code an uncommented url:


http://site.for.this.function.domain/folder/file.html
function theFunction()
{
// do something.
}

Fortunately, everything went fine:

* The ugly part, with many undeclared identifiers, was commented out
by the //.
* http: was interpreted as something, strange.

Actually, it may have something to do with the syntax with which object
literals can be declared in javascript, but I can't understand why. It
seems that I can prefix most, if not all, lines of code, with any
prefix, followed by a colon, without any noticeable effect.

Any insight on this welcome; anyway, this had to be shared :)


Alexis
 
M

Michael Winter

http://site.for.this.function.domain/folder/file.html
function theFunction()
{
// do something.
}
[snip]

Any insight on this welcome; anyway, this had to be shared :)

As Martin said, the "http:" will be (initially) interpreted as a labelled
statement. The syntax is simple:

LabelledStatement:
Identifier : Statement

where "Identifier" is any name that conforms to identifier rules, and
"Statement" is any legal statement.

However, a function declaration is not a legal statement so a strict
parser would raise an error when it encountered the theFunction
declaration.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top