QQ said:
could anyone here tell me the difference between
(function(){
)());
There's not much of a difference. Both result in function being
interpreted as function expression, and invoked with empty arguments list..
In first case, function expression itself is surrounded with parenthesis
(grouping operator) and is then appended with arguments (last pair of
parens), resulting in object invocation.
Second expression is fully surrounded with parenthesis (grouping
operator), and itself consists of function expression, followed by
arguments (inner pair of parens). It also results in object invocation.
You can even omit grouping operator altogether (although, generally not
recommended, for the reasons of clarity), as long as invocation happens
within expression context:
1, function(){ return 'foo'; }();
or:
x = function(){ return 'foo'; }();
or (if part of another function):
return function(){ return 'foo'; }()
etc. But not:
function(){ return 'foo'; }();
since in this case it would be interpreted as a statement (and so result
in syntax error).
[...]