所以我看到了一个函数,它的简单性非常坦率地说很漂亮,因为它允许您在匿名函数中找到全局对象(取决于当时的环境可能不是 window );但是,当您抛出 javascripts 的“使用严格”时;由于对关键字“this”的评估发生了变化,它会崩溃。有几种方法可以做到这一点?
(function () {
var win = function () {
return (function () {
return this;
}());
};
//win now points to the global object no matter where it is called.
}());
现在,如果在“使用严格”的上下文中调用这些函数,我们将失去所描述的功能,那么在 ES5 严格模式下是否有任何等价的功能?
以供参考
(function () {
"use strict"
//code here is in strict mode
}())