jquery notes-Plugin development tips

Source: Internet
Author: User

jquery Official document on the recommended development plug-in to the following format to write, I first read the source code when I see this way, was depressed long time.

(function ($) {
Code goes here
}) (JQuery);

The following will record why this is written, and what are the specific benefits of writing this.

In fact, the above method is equivalent to the following definition, but the above method is more secure. Similar to the hidden class in Java, after the definition, a large program to avoid third-party misoperation, thereby destroying the encapsulation.

The above code is equivalent to the following code, I would like to write that everyone can see it.
var jqueryfucntion=function ($) {
Code goes here
//
}
Jqueryfucntion (JQuery);


(function ($) {
Code goes here
})
A jquery function is defined above, and the formal parameter is $


(function ($) {
Code goes here
}) (JQuery);
This is called the previously defined function, and then the jquery argument is passed in.


The advantage of this is that when we write a jquery plugin, we can also use this alias, without causing a conflict with prototype.

If it is not defined in this way, and end-use uses prototype, then there will be irreconcilable contradictions.

jquery notes-Plugin development tips

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.