(function () {}) What is the function and purpose of (jQuery)?

Source: Internet
Author: User

1. Why is the development plugin all written like this?

2, why should I wear jquery in? Is there a way to use jquery directly in the method or not?

1 First (function () {}) () This method creates an anonymous method and executes it immediately (function () {}) This is the parentheses following the anonymous method, which is called immediately.
Doing so creates a scope to ensure that internal variables do not conflict with external variables, such as jquery (the variables defined inside jquery).

2 (function ($) {}) (JQuery) The main function of this writing

or to ensure that jquery does not conflict with other class libraries or variables first is to ensure that the name of jquery is not a conflict with the external (jquery internal $ and jquery is the same thing has two names reason is afraid of $ Conflicts with other variable names two jQuery has a very small chance of collisions with other variables) and passing in anonymous objects, the anonymous object is named $ (actually the same as in jquery) and then you can be free in (function ($) {}) (jquery) Write your plugin without having to consider whether there is a conflict with the external variables

(function () {}) What is the function and purpose of (jQuery)?

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.