The function object in JS is a fascinating thing, but because he is too flexible and often confusing, I post some code:
Most people have this shorthand:
Copy Code code as follows:
The whole book of the Jsvascript language:
Copy Code code as follows:
var test = function () {}
Functions can run immediately and assign values:
Copy Code code as follows:
var test = function () {} ()//test = = undefined
var test2 = function () {return ' Sugar Pie '} ()//Test2 = = ' Sugar Pie '
But the function shorthand does not run directly, the following code will complain:
Copy Code code as follows:
function Test () {} ()//Syntaxerror:syntax Error
Normal after wrapping with the "()" Run:
Copy Code code as follows:
(function Test () {}) ();
In fact, this function name test has no meaning, the removal of the anonymous function, can still automatically execute the function in vivo code, commonly used to write anonymous functions:
Copy Code code as follows:
Anonymous functions can also be said to be "beautiful" point:
Copy Code code as follows:
See this, just contact JS brother is it going crazy? I have seen my project to engage in C-language cab, I saw the anonymous function immediately after the petrochemical ...