Function.prototype.call或Function.protoype.apply与异步函数的语法是什么



在处理async函数时,使用call()apply()方法更改this的语法是什么?

举个例子:

class Foo {
async someLongMethod(){
... Do stuff
}
}
class Bar {
async someOtherMethodThatWillWait(){
//Will the following work?
await Foo.prototype.someLongMethod.call(this);
... Do stuff but only after someLongMethod has completed
}
}

它与调用普通函数的语法完全相同,没有区别。您无法真正区分一个async function和任何其他返回promise的function

相关内容

最新更新