JS self-invocation anonymous function to implement _JAVASCRIPT skills

Source: Internet
Author: User
Tags anonymous function definition
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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.