In js, a function is often defined as a temporary namespace. Variables defined in this namespace will not pollute the global namespace (to prevent conflicts between local variables and global variables).
function mymodule(){
//module code
}
mymodule();
can be abbreviated as:
(function(){ //mymodule() function is rewritten as an anonymous function expression
//module code
}( )); //End the function definition and call it immediately
or:
(function(){
}) ();
This way of defining an anonymous function and calling it immediately (self-calling the anonymous function) has become very common, and it is starting to make people a little confused. The source code of jquery is like this Written:
(function( window, undefined ) {
//All code of jquery
})( window );
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn