module.exports vs. export default in Node.js und ES6
Was ist der Unterschied zwischen Node'smodule.exports
und ES6'sexport default
? Ich versuche herauszufinden, warum ich den Fehler "__ ist kein Konstruktor" erhalte, wenn ich versuche,export default
in 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
Was does Arbei'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