function(){}();

  • Thread starter ballpointpenthief
  • Start date
H

Henry

Henry a écrit :


Is this supposed to be wrong ?

Where a function is concerned the only thing that is right about not
having any source code is that the absence of code avoids syntax
errors.
 
B

Bruno Desthuilliers

Henry a écrit :
Where a function is concerned the only thing that is right about not
having any source code is that the absence of code avoids syntax
errors.

Indeed !-)

But what I meant was : is this (I mean, the OP snippet) supposed to be
wrong *wrt/ language specs* ? AFAICT it should be legal - even if
obviously useless ?
 
A

AKS

AFAICT it should be legal - even if obviously useless ?

This expression contradicts the specification which says:

12.4 Expression Statement
Syntax
ExpressionStatement :
[lookahead ∉ {{, function}] Expression ;
... an ExpressionStatement cannot start with the function keyword
because that might make it ambiguous with a FunctionDeclaration.
 
B

ballpointpenthief

AFAICT it should be legal - even if obviously useless ?

This expression contradicts the specification which says:

12.4 Expression Statement
Syntax
ExpressionStatement :
[lookahead ∉ {{, function}] Expression ;
... an ExpressionStatement cannot start with the function keyword
because that might make it ambiguous with a FunctionDeclaration.

The corrected version is:
(function(){})();
 
H

Henry

Henry a écrit :


Indeed !-)

But what I meant was : is this (I mean, the OP snippet) supposed to be
wrong *wrt/ language specs* ? AFAICT it should be legal - even if
obviously useless ?

And what I meant (I said pretty explicitly) was that there was no
snippet in the OP to judge.
 
C

Csaba Gabor

This expression contradicts the specification which says:
12.4 Expression Statement
Syntax
ExpressionStatement :
[lookahead ∉ {{, function}] Expression ;
... an ExpressionStatement cannot start with the function keyword
because that might make it ambiguous with a FunctionDeclaration.

The corrected version is:
(function(){})();

Please see posts 2 and 5 of the following April 10, 2006 thread for a
more detailed explanation:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/bff638ebc5a4fe21/

Csaba Gabor from Vienna
 
D

Dr J R Stockton

In comp.lang.javascript message <173d0b5e-74d4-4b84-b24e-e33fbbbffc3e@e2
5g2000prg.googlegroups.com>, Fri, 7 Dec 2007 03:44:11, ballpointpenthief
What's wrong with this function?

Reading FAQ 2.3 para 2 sentence 2 will help you to understand other
replies.
 

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,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top