exports 和 module.exports 的区别

前端之家收集整理的这篇文章主要介绍了exports 和 module.exports 的区别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

require 用来加载代码,而 exports 和 module.exports 则用来导出代码。exports 和 module.exports 的区别:
区别二者,只需明白下面四句话:

  1. node自动创建module、exports对象,module对象拥有exports属性

  2. module.exports 初始值为一个空对象 {}

  3. exports 是指向 module.exports 的引用

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

猜你在找的程序笔记相关文章