JS often defines a function as a temporary namespace in which variables defined within the namespace do not contaminate the global namespace (preventing local and global variables from being conflicted).
Copy Code code as follows:
function MyModule () {
Module code
}
MyModule ();
can be abbreviated as:
Copy Code code as follows:
(function () {//mymodule () function overrides to anonymous functional expression
Module code
} () <span style= "color: #ff0000;" >) </span>; End Function definition and call it now
Or:
Copy Code code as follows:
(function () {
}<span style= "color: #ff0000;" >) </span> ();
This definition of anonymous functions and immediate invocation (from the call anonymous function) has been very common, beginning to be a bit confusing, the source of jquery is written in this way:
Copy Code code as follows:
(Function (window, undefined) {
All the code for jquery
}) (window);