开发者

What jQuery was exposed?

jQuery is exposed via:

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

But there are two jQuery:

var jQuery = (function() {

// 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, rootjQuery );
    },

i understand that it's legitimate names开发者_开发问答 - they're from different scope. But which one was exposed? i suppose it's var jQuery = function( selector, context ) but it seems it's in different scope from window.jQuery = window.$ = jQuery;


I assume you're looking at src/core.js and src/outro.js.

At the top of core.js, there is this code (as shown in your question):

var jQuery = (function() {

// Define a local copy of jQuery
var jQuery = function( selector, context ) {

That, on its own, might look like it's assigning a new function to jQuery. However, if you look at the bottom:

return jQuery;

})();

It's executing a function that it just created, and setting jQuery to the result (which is the jQuery from inside the function).

Then, in outro.js, there is this code:

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

jQuery here is the jQuery from the top of core.js. Thus, through a series of steps, it is setting window.jQuery (as well as window.$) to the jQuery object defined like this:

// 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, rootjQuery );
    },
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜