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 token上MyClass.这是为什么?不能使用静态功能await或者我犯了错误?
谢谢
await运算符只能在异步函数中使用.
(async () => {
try {
const result = await MyClass.getSmthg();
} catch(e) {}
})()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11933 次 |
| 最近记录: |