The general structure of jQuery learning notes

  • 2020-03-30 03:08:03
  • OfStack

Let's look at the code first:


(function (window, undefined) {
            //Building jQuery objects
            var document = window.document,
                navigator = window.navigator,
                location = window.location;
            var jQuery = (function () {
                var jQuery = function (selector, context) {
                    return new jQuery.fn.init(selector, context, rootjQuery);
                },
                _jQuery = window.jQuery;
                //............................
                //............................                  
                return jQuery; //Line 981
            })();
            //Tool methods :Utilities; I did not find which part in the jQuery source code, if found. Can tell me
            //Callbacks list of Callbacks
            //Asynchronous queue delay
            //Browser functionality test Support
            //Data cache & NBSP; The Cache
            //Property operation & NBSP; The Attributes
            //Queue Queue
            //Event system Event
            //The selector Sizzle
            //Dom traversal Traversing
            //Dom Manipulation operation
            //Style manipulation CSS
            //Asynchronous request Ajax
            //Animation Effects
            //Coordinate Offset. Dimensions
            window.jQuery = window.$ = jQuery;
        })(window);

1. This is the structure of the source code of jQuery.

2. The entire outermost layer of jQuery is an anonymous function that is called by itself, so that a closure can be created. The various variables in the closure, the function will not affect the variables and functions outside the closure, ensuring the independence and security of jQuery.

Window. jQuery = window.$= jQuery; Defines a global variable jQuery and $. Assigns a reference to the private variable jQuery to the global variable.

4. The largest object window is passed into the function as an argument, making the window become a local variable, which can greatly shorten the search time for window and save resources.

5, the second parameter undefined, is a parameter, in the actual execution, did not get the parameter assignment, then the system will automatically assign it to undefined.


Related articles: