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
Run Code Online (Sandbox Code Playgroud)
'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 …Run Code Online (Sandbox Code Playgroud)