jQuery internals: Organization of the jQuery Object

Posted by sonofdelphi on Stack Overflow See other posts from Stack Overflow or by sonofdelphi
Published on 2010-05-28T10:28:40Z Indexed on 2010/05/28 10:31 UTC
Read the original article Hit count: 288

Filed under:
|

I was going through the source code of jQuery. I'm having trouble understanding the wrapping strategy for the jQuery object.

(function( window, undefined ) {

    // Define a local copy of jQuery
    var jQuery = function( selector, context ) {
            // The jQuery object is actually just the init constructor 'enhanced'
            return new jQuery.fn.init( selector, context );
        },

    ....
    ....
    ....

    // Expose jQuery to the global object
    window.jQuery = window.$ = jQuery;

})(window);

Specifically, what I'm not able to understand stems from the first line.

  1. What is the outermost unnamed container function? Why is it required?

  2. Why is the container function anonymous?

  3. What is the need for the outermost '(' parantheses ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery