The only observable difference is a very specific. It related with ASI
(automatic semicolon insertion) mechanism. E.g.
Version 1:
var foo = function () {
return "foo";
}
(function () {
return "IIFE";
})();
Version 2:
var foo = function () {
return "foo";
}
(function () {
return "IIFE";
}());
The version 1 fails, the second one -- does not. Why? Which changes to
provide for that version 1 don't fail?
But as mentioned, this case is very specific and just academical. In
real practice, only the convenience in this case does matter.
(function () {})(); -- here first we get a FE (evaluating the expression
inside the grouping operator) and the call it.
(function () {}()); -- here we evaluate the grouping operator which
directly evaluates the function execution.
Additional info:
http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses
Dmitry.
On 15.02.2011 11:53, Ivan S wrote:
Hi all.
I don't know ECMA script specification so well, so if someone can
explain what's the difference between this two:
(function() {
}());
(function() {
})();
(brackets have different positioning)
Intuitively, I can understand the difference, but I would like
technical explanation.
Thank you very much.
Ivan
--
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]
--
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]