(function ($) {...}) (JQuery) a JS plugin notation

Source: Internet
Author: User

Let's first look at the contents of the first parenthesis: function ($) {...}, is this an anonymous function? But its formal parameter is more strange, is $, here is mainly to do not conflict with other libraries.

This makes it easier to understand that the first parenthesis is defined as an anonymous function, and we call the function with parentheses and arguments behind the function name, but because the operator's precedence we define the anonymous function to be enclosed.

Now I think we have a good idea of what this sentence means. The first parenthesis indicates that an anonymous function is defined, and then the second function represents the argument passed by the function, and the entire combination means that an anonymous function is defined and then called, and the function's argument is jquery.

Equivalent: function Fun ($) {...}; Fun (jQuery);

This method is mostly used for the development of plug-ins, when executing the code, the DOM object does not necessarily load complete.

The opposite is $ (function () {}), which is used when the DOM object of the page is loaded.

In fact, the full write of this method is: $ (document). Ready (function () {});

(function ($) {...}) (JQuery) a JS plugin notation

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.