On 31.12.2010 19:16, Marc Harter wrote:
The correct and full explanation is here: 
http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses
This is good Dmitry, thanks for sharing, I understood what you could and could 
not do but didn't know the reasons to that depth.


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);

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.

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