为什么第二个函数没有使用“use strict”;模式(它在控制台中显示窗口对象):
function test() {
console.log(this);
}
test(); // will be global or window, it's okay
"use strict";
function test2() {
console.log(this);
}
test2(); // will be global, BUT WHY? It must be undefined, because I have used strict mode!
但是如果我在第二个函数的主体中定义严格模式,一切都会如我所料。
function test() {
console.log(this);
}
test(); // will be global or window
function test2() {
"use strict";
console.log(this);
}
test2();
我的问题很简单——为什么会这样?