JQuery source code learning notes: overall architecture

Source: Internet
Author: User

1.1 self-called anonymous functions:

(Function (window, undefined) {// jquery code}) (window );

This is a self-called anonymous function. The first bracket is an anonymous function, the second bracket is executed immediately, and the input parameter is window.

1. Why does a self-called anonymous function exist?

By defining an anonymous function, a "private" space is created. jQuery must ensure that the created variable cannot conflict with the program that imports it.

2. Why input a window?

The input window changes the window from a global variable to a local variable. When jQuery accesses the window, it does not need to return to the top-level scope to allow faster access to the window. More importantly, it can be optimized when the code is compressed.

3. Why does undefined exist?

Within the scope of self-called anonymous functions, make sure that undefined is really undefined. Because undefined can be rewritten.

1.2 overall architecture:

(Function (window, undefined) {// construct the jQuery object var jQuery = function (selector, context) {return new jQuery. fn. init (selector, context, rootjQuery );} // tool function Utilities // asynchronous queue Deferred // browser test Support // Data cache Data // queue // Attribute operation Attribute // Event processing // selector Sizzle // DOM traversal // DOM operation // CSS operation // asynchronous request Ajax // animated FX // coordinate and size 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.