最佳答案
Node的module.exports
和ES6的export default
之间的区别是什么?我试图弄清楚为什么当我尝试在Node.js 6.2.2中export default
时,我会得到“__不是构造函数”错误。
'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