anonymous function, which is a function without a name. Such as:
Copy Code code as follows:
function () {
Alert (' a function ');
}
However, the above code will make an error. Firebug hint: Function statement requires a name, which means that the functions must have a name.
Oddly enough, if I wrap a pair of functions with no name, there's no error. Such as:
Copy Code code as follows:
(function () {
Alert (' a function ');
})
(Note the package function ()!). Although this will not be an error, who can tell if the function is declared successful? Is it because there is no statement so that you do not complain? We test this: let the function execute itself once:
Copy Code code as follows:
(function () {
Alert (' a function ');
}())
As you can see, the function is executed, indicating that the function exists.
Similarly, if you remove the wrapping function () at this time, you will still report the previous error, the function can not perform ...
Copy Code code as follows:
function () {
Alert (' a function ');
}()
Is this really so important to the wrapping function ()? Which expert explains the principle?