参考Promise.All
此代码有效:
Promise.all([Promise.resolve(1)])
但是,此代码不:
const f = Promise.all
f([Promise.resolve(1)])
第二件代码列出以下错误: und offerate typeerror:Promise.All in non-object
。
为什么我不能将函数承诺分配给变量并正常使用?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为那是规格要求。
您当前的代码不是将函数称为对象的一部分(即,
f
是独立标识符),因此结果是全局对象或>未定义的
,取决于您是否处于严格模式 - 无论哪种方式,上述要求都无法满足。如果将功能绑定到承诺,它将起作用。
Because that's what the spec requires.
Your current code is not calling the function as part of an object (that is,
f
is a standalone identifier), so the resultingthis
is either the global object orundefined
, depending on whether you're in strict mode or not - either way, the above requirement is not fulfilled.If you bind the function to Promise, it'll work.