开发者

Passed in undefined argument in jQuery core source code

I noticed that in the jQuery core, one of the two arguments passed in is undefined.

(function( window, undefined ) {

    // Use the correct document accordingly with window argument (sandbox)
    var document = window.document;
    var jQuery = (function() {
        // ...defintion of t开发者_StackOverflow中文版he rest of the core...
    window.jQuery = window.$ = jQuery;
})(window);

Can anyone explain why the second argument is undefined?

Thanks in advance!


Undefined is a type but is also a global variable.

You can have a module that overwrites the value of undefined by doing undefined = whatever.

jQuery uses a immediate function to scope window and undefined.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/undefined


Since someone could overwrite undefined like this

undefined = true;

Code of your immediate function will pass it as it should be (stay undefined). I think it's mentioned in 10 Things I Learned from the jQuery Source.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜