开发者

why do we need to pass in window and undefined into this jquery plugin? [duplicate]

This question already has answers here: What is the purpose of passing-in undefined? (3 answers) Closed 8 years ago.

I'm looking at jquery resize plugin and can't understand certain things about how it works:

usually we only pass in Jquery object into jquery plugins, like this:

(function($){
    ....plugin code....
})(jQuery);

In "resize" plugin there are window and undefined objects being passed in:

(function($,window,undefined){
    ....plugin code....
})(jQuery,this);

IMHO - win开发者_如何学Godow is a global object anyway - why do we need to pass it in? the logic behind passing in undefined object I understand even less. I'm sure there's gotta be some reason for it - but I cannot think of any.

Can someone explain why is it being done?


this is explained very well in this video.

basically, you can set those variables in the self invoking function to ensure they work as expected.

"the asshole effect" undefined = true; -paul irish

furthermore by passing these as arguments they can also be minified.

ie.

(function(A,B,C){
    ....plugin code....
})(jQuery,this);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜