jQuery Deconstruction | What does this refer to?
<p>What does this refer to in the init function below from <a href="http://code.jquery.com/jquery-latest.js" rel="nofollow">jQuery latest</a></p>

<p>When a method is called from an object, this usually refers to the object that holds the method.</p>

<p>However in this case the method is called using the new keyword.</p>

<p>Does this change what this points to or does it still point to the object that holds the the method, in this case that would be - <code>jQuery.fn.init()</code></p>

<p><strong>jQuery Deconstruction</strong></p>

<p><strong>jQuery is globalized like this:(line 9422)</strong></p>

<pre><code>window.jQuery = window.$ = jQuery;
</code></pre>

<p><strong>jQuery is defined here:(line 42)</strong></p>

<pre><code>jQuery = function( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    return new jQuery.fn.init( selector, context, rootjQuery );
},
</code></pre>

<p><strong>jQuery.fn.init is defined here:(line 95)</strong></p>

<pre><code>jQuery.fn = jQuery.prototype = {
    constructor: jQuery,
    init: function( selector, context, rootjQuery ) {
        var match, elem, ret, doc;

        // Handle $(""), $(null), $(undefined), $(false)
        if ( !selector ) {
            return this;
        }

        // Handle $(DOMElement)
        if ( selector.nodeType ) {
            this.context = this[0] = selector;
            this.length = 1;
            return this;
        }

        // Handle HTML strings
        if ( typeof selector === "string" ) {
            if ( selector.charAt(0) === "&lt;" &amp;&amp; selector.charAt( selector.length - 1 ) === "&gt;" &amp;&amp; selector.length &gt;= 3 ) {
                // Assume that strings that start and end with &lt;&gt; are HTML and skip the regex check
                match = [ null, selector, null ];

            } else {
                match = rquickExpr.exec( selector );
            }

            // Match html or make sure no context is specified for #id
            if ( match &amp;&amp; (match[1] || !context) ) {

                // HANDLE: $(html) -&gt; $(array)
                if ( match[1] ) {
                    context = context instanceof jQuery ? context[0] : context;
                    doc = ( context &amp;&amp; context.nodeType ? context.ownerDocument || context : document );

                    // scripts is true for back-compat
                    selector = jQuery.parseHTML( match[1], doc, true );
                    if ( rsingleTag.test( match[1] ) &amp;&amp; jQuery.isPlainObject( context ) ) {
                        this.attr.call( selector, context, true );
                    }

                    return jQuery.merge( this, selector );

                // HANDLE: $(#id)
                } else {
                    elem = document.getElementById( match[2] );

                    // Check parentNode to catch when Blackberry 4.6 returns
                    // nodes that are no longer in the document #6963
                    if ( elem &amp;&amp; elem.parentNode ) {
                        // Handle the case where IE and Opera return items
                        // by name instead of ID
                        if ( elem.id !== match[2] ) {
                            return rootjQuery.find( selector );
                        }

                        // Otherwise, we inject the element directly into the jQuery object
                        this.length = 1;
                        this[0] = elem;
                    }

                    this.context = document;
                    this.selector = selector;
                    return this;
                }

            // HANDLE: $(expr, $(...))
            } else if ( !context || context.jquery ) {
                return ( context || rootjQuery ).find( selector );

            // HANDLE: $(expr, context)
            // (which is just equivalent to: $(context).find(expr)
            } else {
                return this.constructor( context ).find( selector );
            }

        // HANDLE: $(function)
        // Shortcut for document ready
        } else if ( jQuery.isFunction( selector ) ) {
            return rootjQuery.ready( selector );
        }

        if ( selector.selector !== undefined ) {
            this.selector = selector.selector;
            this.context = selector.context;
        }

        return jQuery.makeArray( selector, this );
    },
</code></pre>

<p><strong>makeArray is defined here:(line 637)</strong> // not used in basic selection on an id</p>

<pre><code>makeArray: function( arr, results ) {
    var type,
        ret = results || [];

    if ( arr != null ) {
        // The window, strings (and functions) also have 'length'
        // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
        type = jQuery.type( arr );

        if ( arr.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( arr ) ) {
            core_push.call( ret, arr );
        } else {
            jQuery.merge( ret, arr );
        }
    }

    return ret;
},
</code></pre>
