On the initialization of jquery and the construction of object _jquery

Source: Internet
Author: User
Summary:

1. The whole class library is defined in an anonymous function, which eliminates the generation of global variables;
2. The undefined is passed as missing parameter to prevent the pollution of the undefined variable;
3. You can see that $ (...) actually returns an instance of the JQuery.fn.init object and then points the object's prototype to the Jquery.prototype (statement jQuery.fn.init.prototype = JQUERY.FN), the resulting instance shares the methods and attributes in Jquery.prototype and realizes the operation of chained programming;
4. Finally through window.jquery = window.$ = jquery, jquery and $ are exported as global variables.

Copy Code code as follows:
(function (window, undefined) {
//Define a local copy of JQuery
VA R JQuery = (function () {
var jQuery = function (selector, context) {
//The jquery object is actually just the Init constructor ' enhanced '
Return to new JQuery.fn.init (selector, context/*, rootjquery*/);
};
//...
Jquery.fn = Jquery.prototype = {
Constructor:jquery,
Init:function (selector, context, rootjquery) {
//...
}
//...
};
//Give the INIT function the JQuery prototype for later instantiation
JQuery.fn.init.prototype = Jquery.fn;
//...
//Expose jquery to the global object
return jquery;
}) ();
//...
Window.jquery = window.$ = 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.