为什么我们需要传入window和undefined到这个jquery插件? [英] why do we need to pass in window and undefined into this jquery plugin?

查看:424
本文介绍了为什么我们需要传入window和undefined到这个jquery插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看jquery 调整大小插件,可以'了解它是如何工作的某些事情:

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

通常我们只将Jquery对象传递给jquery插件,如下所示:

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 - window 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.

混蛋效果 undefined = true; -paul irish

"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);

这篇关于为什么我们需要传入window和undefined到这个jquery插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆