kub*_*003 11 javascript commonjs node.js ecmascript-6
我正在尝试从Node.js 6.2.0中的CommonJS模块导出ES6类
class MyClass{
//class contents here
}
exports = MyClass;
Run Code Online (Sandbox Code Playgroud)
然后在另一个模块中导入它:
var MyClass = require('/path/to/module.js')
var instance = new MyClass();
Run Code Online (Sandbox Code Playgroud)
但是我得到以下异常:
TypeError: MyClass is not a constructor
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
请注意,我没有使用Babel/Tranceur,它是纯粹的JS,在最新的Node 6.2.0中实现,根据Kangax,93%实现了ES6.
//编辑:这对export和module.exports来说不是问题.虽然单独使用导出,但我得到了一些__proto__set的对象.
Ber*_*rgi 27
您需要分配module.exports,而不是本地exports变量.
| 归档时间: |
|
| 查看次数: |
20274 次 |
| 最近记录: |