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?
this. functionName reads the value of property functionName of the object this . this. functionName() reads the value of property functionName of the object this and tries to call it as a function.
In regular function, arguments will give you list of parameter passed in function, In arrow function arguments is not defined. In regular function, you always have to return any value, but in Arrow function you can skip return keyword and write in single line. In arrow function parameters should be unique.
Use this article as a reference sheet for JavaScript methods and functions. Function — a set of instructions that perform a task. Method — a set of instructions that are associated with an object.
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 the FunctionExpression
:
CallExpression | | FunctionExpression | | | V V (function() { }()); ^ ^ |--PrimaryExpression --|
In the second example, we have first a whole CallExpression
, that holds the FunctionExpression
:
PrimaryExpression | FunctionExpression | V (function() { })(); ^ ^ |-- CallExpression --|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With