所以我看到一个函数,它的简单性非常坦率,因为它允许你在匿名函数中找到全局对象(当时依赖于环境可能不是窗口); 但是当你抛出javascripts的"use strict"时; 由于关键字'this'的变化评估,它会崩溃.有几种方法可以实现这一目标?
(function () {
var win = function () {
return (function () {
return this;
}());
};
//win now points to the global object no matter where it is called.
}());
Run Code Online (Sandbox Code Playgroud)
现在,如果在"use strict"的上下文中调用它们,我们将失去所描述的功能,是否有任何可以在ES5严格模式下完成的等效操作?
以供参考
(function () {
"use strict"
//code here is in strict mode
}())
Run Code Online (Sandbox Code Playgroud)