As noted in Note 1, the overall structure of jQuery is as follows:

(function( global, factory ) {
    // Call factory to generate a jQuery instance
    factory( global); } (typeof window! = ="undefined" ? window : this.function( window, noGlobal ) {
    // Factory implementation, jquery source code body part
}));
Copy the code

What about the factory that generates jQuery?

Brief:

function( window, noGlobal ) {

    var jQuery = function( selector, context ) {// First define an internal jQuery. Note that this jQuery is only an internal factory variable, not the jQuery or $we referenced outside
        return new jQuery.fn.init( selector, context );
    };

    /* Then, make various enhancements and extensions to the internal jQuery object */
    jQuery.fn = jQuery.prototype = {
        / /...
    };
    jQuery.extend = jQuery.fn.extend = function() {
        / /...
    };
    var init = jQuery.fn.init = function( selector, context, root ) {
        / /...
    };
    init.prototype = jQuery.fn;
    jQuery.extend({
        / /...
    });
    jQuery.fn.extend({
        / /...
    });

    if ( !noGlobal ) {// Finally, we assign the inner jQuery to the outer, known as the "$"
        window.jQuery = window.$ = jQuery;
    }

    return jQuery;
}
Copy the code

From the factory code, $is essentially a function, so we can refer to it like this:

$(".class")
Copy the code