【发布时间】:2018-10-31 07:47:30
【问题描述】:
所以,我有以下 3 个功能:
function a() {
arguments[0]();
}
function b(fn) {
fn();
}
function c() {
console.log(this);
}
现在,考虑输出:
a(c) // Arguments
b(c) // Window
a(() => {console.log(this}) // Window
b(() => {console.log(this)}) // Window
为什么a(c) 在所有其他情况下都是窗口(考虑非严格)时输出参数?
【问题讨论】:
-
这里唯一看似奇怪的情况是第一个。与
foo.bar(),foo将是这个。这等价于foo["bar"](),因此也等价于arguments[0]()。 -
因为
arguments[0]();是一个方法调用。 -
谢谢@Bergi。我花了一段时间才明白这一点
标签: javascript arguments this