Differences between anonymous functions in jQuery

Source: Internet
Author: User

Example

Differences between the two methods in jQuery

The code is as follows: Copy code

/*
Make sure that jQuery can be referenced correctly, because $ may be redefined outside the anonymous function,
Passing jQuery as a parameter to an anonymous function ensures that $ in the function is jQuery.
*/

(Function ($ ){
// Code Here...
}) (JQuery)

/*

$ (Document). ready () refers to a function passed to $ (). This function will be executed when DOM loading is complete.
*/

$ (Function (){
// Code Here...
})

Most of the time,

The code is as follows: Copy code

(Function ($ ){...}) (Jquery );

In the context environment, the parameter jquery does not exist. Therefore, in the jquery anonymous function, the user creates a jquery object.

I will give a brief description here,

The code is as follows: Copy code

(Function ($ ){...}) (Jquery );

And

A = function ($ ){...};

A (jquery );

Equivalent.

Therefore, this method is used to allow anonymous functions to be executed immediately.

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.