B
ballpointpenthief
What's wrong with this function?
What's wrong with this function?
The total absence of any source code.
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.
AFAICT it should be legal - even if obviously useless ?
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.
On Dec 7, 1:21 pm, AKS <[email protected]> wrote:
The corrected version is:
(function(){})();
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 ?
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(){})();
What's wrong with this function?
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.