The function (...) {...}
is an expression of a function, that is, an expression representing a function. The only reason it should be enclosed in parentheses in this case is because if the keyword function
is the very first thing in the instruction, then the operator is considered the operator of the function, that is, the declaration of the function. (In fact, it does not have to be enclosed in parentheses, it also works to prefix it with +
or even put any kind of token in front of the function
, which prevents the interpretation of the operator function.)
The part ()
after the expression of the function coincides with the normal ()
for calling the function. It:
(function (...) {...})(...);
(except for the temporary variable), same thing:
var f = function (...) {...}; f();
which is equivalent to this:
function f(...) {...}; f();
source share