调用异步静态函数时的SyntaxError

Nor*_*cUs 8 javascript node.js async-await

我正在使用Node 8.3.0的异步/等待,我有一些静态功能的问题.

MyClass.js

class MyClass {
  static async getSmthg() {
    return true;
  }
}
module.exports = MyClass
Run Code Online (Sandbox Code Playgroud)

index.js

try {
  const result = await MyClass.getSmthg();
} catch(e) {}
Run Code Online (Sandbox Code Playgroud)

有了这个代码,我有一个SyntaxError: Unexpected tokenMyClass.这是为什么?不能使用静态功能await或者我犯了错误?

谢谢

End*_*ess 8

await运算符只能在异步函数中使用.

(async () => {
  try {
    const result = await MyClass.getSmthg();
  } catch(e) {}
})()
Run Code Online (Sandbox Code Playgroud)