gpt4 book ai didi

javascript - 在 Chrome 中,JS 绑定(bind)函数具有 null arguments.callee.caller

转载 作者:行者123 更新时间:2023-11-30 18:32:06 24 4
gpt4 key购买 nike

从 Chrome 17 开始,arguments.callee.caller 对于绑定(bind)函数似乎为空:

function a() {
this.test = function() { console.debug('*** ' + arguments.callee.caller); };
this.test(); // This prints the function
this.bound = this.test.bind(this);
this.bound(); // This prints null
}

绑定(bind)和未绑定(bind)函数曾经一致地运行,但现在不是了。

这是预期的行为吗?

最佳答案

也许这不是一个错误。您可能会注意到:
如果函数 f 被顶层代码调用,则 f.caller 的值为 null,否则就是调用 f 的函数。 MDN

当您在函数 a 中使用 this 时,'this' 表示 DOMWindow。因此,当您将绑定(bind)函数绑定(bind)到 this 时,绑定(bind)函数将由顶级代码调用。它返回 null

希望对您有所帮助。 rdtriny.

关于javascript - 在 Chrome 中,JS 绑定(bind)函数具有 null arguments.callee.caller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9371170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com