On 01.01.2011 0:55, Marc Harter wrote:
The thing is that (almost?) all explanations (I repeat -- books, articles, etc) 
talked about `calling`, that is wrong. While the reason is that parentheses at 
the end are not parentheses of a call (`Arguments` production), but just a 
grouping operator (without an expression inside) which causes the error.

function foo(x) {
  alert(x)
}(1);

There is no error. But it's not a call. It's a FD and the following grouping 
operator with the expression `1`. I.e. it's:

function foo(x) {
  alert(x)
}

(1);
So the parses treats these as two distinct statements, that is why a semicolon 
is not automatically inserted after a FD?


Yes, parser already knows that it has a FD here and may itself distinguish two separate constructions. A semicolon was/is never required after FD.

And since an empty grouping operator () causes an error, exactly this is the 
reason:

function foo(x) {
  alert(x)
}();

and not in "FD cannot be _called_", since it's not about calling at all.
This was new to me, I had read or perhaps just assumed it was a call on a FD 
prior, thanks for clearing that up.

I can tell you that it's new for all previous explanations. The thing is really subtle. In case of FD it's a grouping operator. In case when we have a FE (e.g. by using also a grouping operator) the following parentheses are already about the call.

Dmitry.


--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to