nodejs中的exports和module讲解

模块系统

1 是什么

node模块,在一个node执行一个文件时,会给这个文件内生成一个 exports和module对象,而module又有一个exports属性。

2 区别与联系

exports 和 module.exports 指向同一个对象,exports 是 module.exports 的引用。
对 exports 和 module.exports 赋值时要格外注意,明确模块导出的值。
使用 require() 导入模块 A 时,导入的结果是模块 A 中 module.exports 指向的值。

参考文件

  1. node.js的exports、module.exports与ES6的export、export default深入详解
  2. Node.JS中的模块、exports和module讲解
  3. node.js的exports使用误区示例解释
  4. Node.js 中的 module.exports 与 exports区别介绍
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值