匿名调用
调用函数作为匿名函数,this 将成为全局对象(浏览器中的 self)。
function func() {
return this;
}
func() === window; // true
Version = 五
在 ECMAScript 5 的严格模式下 ,如果匿名调用该函数,则 this 将为 undefined。
(function () {
"use strict";
func();
}())
这将输出
undefined
调用函数作为匿名函数,this 将成为全局对象(浏览器中的 self)。
function func() {
return this;
}
func() === window; // true
在 ECMAScript 5 的严格模式下 ,如果匿名调用该函数,则 this 将为 undefined。
(function () {
"use strict";
func();
}())
这将输出
undefined