相关疑难解决方法(0)

Node.js和ES6中的module.exports与export默认值

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)

module node.js ecmascript-6

246
推荐指数
2
解决办法
18万
查看次数

标签 统计

ecmascript-6 ×1

module ×1

node.js ×1