执行下面这段代码时,结果是错误的,为什么?“这个”与什么有关?我期望结果在两个警报语句中都是正确的
(function(win){
alert("this == win: "+ this == win); // false
alert("this == window: "+ this == window); // false
})(window);
与这个不相等的窗口无关,这是一个操作顺序问题....
解析器看到的是:
("this == win: "+ this) == win
添加正确的括号
(function(win){
console.log("this == win: "+ (this == win));
console.log("this == window: "+ (this == window));
})(window);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句