异步类方法返回Function而不是AsyncFunction

时间:2020-07-30 21:04:48

标签: javascript asynchronous

@Edit:我找到了一个“解决方案”。我已经检查了方法的回报。这不是理想的选择,但可以解决我的个人问题。
console.log(name.setName().constructor.name === "Promise")

为什么此方法返回Function而不是AsyncFunction

在节点上运行此代码时,得到AsyncFunction,但是在codesandboxreact 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);

0 个答案:

没有答案