Function objects in js are fascinating, but they are often confusing because they are too flexible. I will post some code below.
Most people are abbreviated as follows:
Function test (){}
The entire book jsvascript is written as follows:
Var test = function (){}
Functions can be run immediately and assigned values:
Var test = function () {} () // test = undefined
Var test2 = function () {return 'sugar browsed '} () // test2 = 'sugar browsed'
However, function abbreviations cannot be run directly. The following code reports an error:
Function test () {} () // SyntaxError: syntax error
If the package is normal after the "()" operator is used:
(Function test (){})();
In fact, this function name "test" is meaningless. After it is removed, it becomes an anonymous function, and the code in the function body can still be automatically executed. Commonly used anonymous function Syntax:
(Function (){})();
The write of anonymous functions may also be "beautiful:
(Function (){}());
From the tmaic Column