Possible Duplicate:
Location of parenthesis for auto-executing anonymous JavaScript functions?
Sometimes I see:
(function() { ... }());
and sometimes I see:
(function() { ... })();
I see both forms with and without arguments. They both execute the anonymous function.
Is there a difference between the two forms? Are there any compelling reasons to use one form over the other?
There is no practical difference in those two forms, but from a grammatical point of view the difference between the two is that The Grouping Operator – the parentheses – will hold in the first example a
CallExpression, that includes theFunctionExpression:CallExpression | | FunctionExpression | | | V V (function() { }()); ^ ^ |--PrimaryExpression --|In the second example, we have first a whole
CallExpression, that holds theFunctionExpression:PrimaryExpression | FunctionExpression | V (function() { })(); ^ ^ |-- CallExpression --|