为什么窗口仍然在此严格模式代码中定义? [英] Why is window still defined in this strict mode code?
本文介绍了为什么窗口仍然在此严格模式代码中定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
"use strict";
setTimeout(function() {"use strict";console.log(this)}, 1000);
setTimeout调用的函数内部的'this'应该引用全局对象,但我也有使用严格;在身体里。然而它记录了窗口而不是未定义,这正是我所期待的。这里发生了什么?
The 'this' inside functions called by setTimeout should refer to global object, but I also have "use strict"; in the body. Yet it logs window instead of undefined, which is what I was expecting. What's happening here?
推荐答案
setTimeout
被定义为调用它在上下文中传递的函数window
。
实现运行算法的方法的对象(Window或WorkerGlobalScope object)作为方法上下文,
the object on which the method for which the algorithm is running is implemented (a Window or WorkerGlobalScope object) as the method context,
它类似于调用 yourfunction.apply(window)
不是 yourfunction()
。
这篇关于为什么窗口仍然在此严格模式代码中定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文