Jak*_*son 9 javascript node.js ecmascript-6
我在Node脚本中有以下内容:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
export default Whatever;
Run Code Online (Sandbox Code Playgroud)
我明白Unexpected reserved word了export.
我在这里错过了什么?如何在外部文件中指定类定义并包含/要求它?
Node.js默认不支持ES6模块.您需要使用--harmonyor --harmony_modules标志激活它们.默认是CommonJS声明(require/ module.exports).
修改代码以支持CommonJS语法:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
module.exports = Whatever;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6839 次 |
| 最近记录: |