469,626 Members | 883 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

function(){}();

What's wrong with this function?
Dec 7 '07 #1
10 1305
On Dec 7, 11:44 am, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
What's wrong with this function?
The total absence of any source code.
Dec 7 '07 #2
Henry a crit :
On Dec 7, 11:44 am, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
>What's wrong with this function?

The total absence of any source code.
Is this supposed to be wrong ?
Dec 7 '07 #3
On Dec 7, 12:25 pm, Bruno Desthuilliers wrote:
Henry a crit :
>On Dec 7, 11:44 am, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
>>What's wrong with this function?
>The total absence of any source code.

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.

Dec 7 '07 #4
Henry a crit :
On Dec 7, 12:25 pm, Bruno Desthuilliers wrote:
>Henry a crit :
>>On Dec 7, 11:44 am, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
What's wrong with this function?
The total absence of any source code.
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.
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 ?
Dec 7 '07 #5
AKS
On 7 дек, 18:10, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
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.
Dec 7 '07 #6
On Dec 7, 1:21 pm, AKS <aksus...@yandex.ruwrote:
On 7 дек, 18:10, Bruno Desthuilliers <bruno.

42.desthuilli...@wtf.websiteburo.oops.comwrote:
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(){})();
Dec 7 '07 #7
AKS
On 7 , 18:33, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
On Dec 7, 1:21 pm, AKS <aksus...@yandex.ruwrote:
>
The corrected version is:
(function(){})();
Yes, of course, and I tell you why - this time you use the grouping
operator (11.1.6 The Grouping Operator), which turns function
statement into valid function expression.

Dec 7 '07 #8
On Dec 7, 1:10 pm, Bruno Desthuilliers wrote:
Henry a crit :
>On Dec 7, 12:25 pm, Bruno Desthuilliers wrote:
>>Henry a crit :
On Dec 7, 11:44 am, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
What's wrong with this function?
The total absence of any source code.
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.

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.
Dec 7 '07 #9
On Dec 7, 2:33 pm, ballpointpenthief <ballpointpenth...@yahoo.co.uk>
wrote:
On Dec 7, 1:21 pm, AKS <aksus...@yandex.ruwrote:
...
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....638ebc5a4fe21/

Csaba Gabor from Vienna
Dec 8 '07 #10
In comp.lang.javascript message <173d0b5e-74d4-4b84-b24e-e33fbbbffc3e@e2
5g2000prg.googlegroups.com>, Fri, 7 Dec 2007 03:44:11, ballpointpenthief
<ba***************@yahoo.co.ukposted:
>What's wrong with this function?
Reading FAQ 2.3 para 2 sentence 2 will help you to understand other
replies.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 8 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by domeceo | last post: by
5 posts views Thread by phil_gg04 | last post: by
2 posts views Thread by laredotornado | last post: by
2 posts views Thread by sushil | last post: by
8 posts views Thread by Olov Johansson | last post: by
3 posts views Thread by Beta What | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.