Node module.exports
和ES6 之间有什么区别export default
?我试图弄清楚为什么export default
在Node.js 6.2.2中尝试出现“ __不是构造函数”错误。
什么有效
'use strict'
class SlimShady {
constructor(options) {
this._options = options
}
sayName() {
return 'My name is Slim Shady.'
}
}
// This works
module.exports = SlimShady
什么不工作
'use strict'
class SlimShady {
constructor(options) {
this._options = options
}
sayName() {
return 'My name is Slim Shady.'
}
}
// This will cause the "SlimShady is not a constructor" error
// if in another file I try `let marshall = new SlimShady()`
export default SlimShady