1.I/O密集的地方尽量不要用require。(require是同步I/O操作)

    eg:正在运行一个HTTP服务器,如果在每个进入的请求上都用了require,就会遇到性能问题。所以通常在程序最初加载时才能使用require和其他同步操作。

2.exports 和 module.exports

  (1)exports 是指向 module.exports 的引用。

  (2)module.exports 初始值是一个空对象 {},so , exports 初始值也是 {}

  (3)require() 返回的是 module.exports 而不是 exports

    注意:exports = function(){}  这种写法是错误的。这会使exports指向一块新内存,使 module.exports 和 exports 不存在任何关系。

    eg:想导出一个对象,exports 和 module.exports 都可使用。除此之外都要用 module.exports.

相关文章:

  • 2022-01-19
  • 2022-12-23
  • 2021-10-29
  • 2021-06-18
  • 2021-05-13
猜你喜欢
  • 2021-05-26
  • 2022-01-21
  • 2021-05-31
  • 2022-12-23
  • 2021-04-28
  • 2021-11-19
  • 2021-09-18
相关资源
相似解决方案