@Edit:我找到了一个“解决方案”。我已经检查了方法的回报。这不是理想的选择,但可以解决我的个人问题。
console.log(name.setName().constructor.name === "Promise")
为什么此方法返回Function
而不是AsyncFunction
在节点上运行此代码时,得到AsyncFunction
,但是在codesandbox或react project上运行时,则得到Function
。
class Name {
constructor(name) {
this.myName = name;
}
async setName(newName) {
this.myName = newName;
}
getName() {
return this.myName;
}
}
const name = new Name();
console.log(name.setName.constructor.name);