我看过这样的例子
(function($, window, undefined) {
...
// Do awesome stuff
...
})(jQuery, this);
我知道将jQuery作为参数传递并以$接收。
这样做是为了避免jquery的$与任何全局变量$(由错误或某些第三方库定义)之间发生冲突。
人们为什么在函数参数中传递this
并接收window
并接收undefined
?
有什么方法可以覆盖window和undefined吗?
PS:我已经在Chrome中尝试过
undefined = 2; // 2
undefined == 2; // false
证明undefined不能被覆盖。
试试这个
function test () {
var undefined = 2; // 2
console.log(undefined == 2); // true
var window = 5; // 5
console.log(window == 5); // true
}
我相信您可以更改undefined
和window
内部的值function
,但不能在global
范围内更改
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句