node中exports和module.exports的关系及使用
在node中,需要记住,在使用exports和module.exports的时候,实际输出的是module.exports。
exports指向module.exports,是module.exports的引用,所以,当使用 exports.a = x 的时候,通过引用关系,造成了module.exports.a = x。当使用 exports = x 的时候,造成了exports不再指向module.exports,所以,仅改变了exports,并没有改变module.exports,也就并没有对输出起作用。
当 exports.a = x 和 module.exports.a = xx 一起使用时,最后输出出来的 a = xx;因为一般我们会把module.exports.a == xx放到后面来写,实际上等效于 module.exports.a = x ,然后又执行了module.exports.a = xx,只是进行了一个重新赋值。
同样,当 exports.a = x 和 module.exports = xx一起使用时,最后的输出只有 xx,我们再来进行一次转化, exports.a = x 等效于module.exports.a = x, 等效于 module.exports = {a: x}, 然后又执行了module.exports = xx, 实际也是进行了一个重新赋值。
node中exports和module.exports的关系及使用的更多相关文章
- node.js中的exports和module.exports
不同的编程语言都有各自的代码组织和复用的方式,如.net.php中的命名空间,python中的import,ruby中的module等,来避免命名空间污染.一直都没搞清楚node中的exports和m ...
- node.js模块中exports和module.exports的区别
Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个模块,有自己的作用域.在一个文件里面定义的变量.函数.类,都是私有的,对其他文件不可见. CommonJS规范规定 ...
- Node.js中exports与module.exports的区别
原文:http://www.hacksparrow.com/node-js-exports-vs-module-exports.html 你肯定对Node.js模块中用来创建函数的exports对象很 ...
- Node.js exports与module.exports的关系
今天搜索module.exports时看到CNode社区上发的Hack Sparrow一篇相关文章的链接 Node.js Module – exports vs module.exports 一篇5年 ...
- Node.js中exports,module.exports以及require方法
在Node.js中,使用module.exports.f = ...与使用exports.f = ...是一样的,此时exports就是module.exports的一种简写方式.但是,需要注意的是, ...
- Node.js 中 exports 和 module.exports 的区别
每一个模块中都有一个 module 对象, module 对象中有一个 exports 对象 我们可以把需要导出的成员都放到 module.exports 这个接口对象中,也就是 module.exp ...
- Node.js中的exports与module.exports的区分
1. module应该是require方法中,上下文中的对象 2. exports对象应该是上下文中引用module.exports的新对象 3. exports.a = xxx 会将修改更新到mod ...
- (译)Node.js的模块-exports和module.exports
原文标题:Node.js Module – exports vs module.exports 原文链接:http://www.hacksparrow.com/node-js-exports-vs-m ...
- Node.js模块导出module.exports 和 exports,Es6模块导出export 和export default的区别
1.module.exports module变量代表当前模块.这个变量是一个对象,module对象会创建一个叫exports的属性,这个属性的默认值是一个空的对象: module.exports ...
随机推荐
- 葵花宝典之机器学习:全网最重要的AI资源都在这里了(大牛,研究机构,视频,博客,书籍,Quora......)
https://blog.csdn.net/wemedia/details.html?id=42039
- Shell、Xterm、Gnome-Terminal、Konsole简介(转)
什么是Shell? 简单的说, Shell就是一个小程序,这个小程序可以接受来自键盘的命令并把这些命令发送到操作系统,再有系统来执行.在过去,在安装有Unix的计算机上,这是唯一的可用的交互式操作.而 ...
- linux命令用来查看日志关键字
1.查看日志 前 n行: cat 文件名 | head -n 数量 demo: cat test.log | head -n 200 # 查看test.log前200行 2.查看日志 尾 n行: c ...
- 手游server之数据IO进化
这里数据IO是指游戏数据存盘和读取. 假设IO处理不好.server在IO时会导致.游戏卡顿较长的时间,严重影响游戏体验. 近期服务端刚好对IO这一块做了优化,把优化过程记录一下. 一 原始版 刚開始 ...
- Linux命令(十一)——Shell程序设计二(循环控制语句)
1.if语句 (1)两路分支的if语句 (2)多路条件判断分支的if语句 2.测试语句 (1)文件测试 (2)字符串测试 (3)数值测试 (4)用逻辑操作符进行组合的测试语句 3.case语句 4.f ...
- 消息推送之百度云推送Android集成与用法
这两天因为项目须要.研究了一下百度云推送,本来这事没什么多大工作量的,但注冊百度开发人员账户创建应用令我蛋疼菊紧了好一阵,这些东西做了对技术没啥提升,不做又不行,必经之路. 好在我耗费了N多个毫毫秒秒 ...
- leetCode 74.Search a 2D Matrix(搜索二维矩阵) 解题思路和方法
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- luogu2508 [HAOI2008]圆上的整点
题目大意 给出\(r\),求圆\(x^2+y^2=r^2\)上坐标均为整数的点数.\(n<=2,000,000,000\) 总体思路 我们看到这个数据大小,还是个数学题,想到这个的时间复杂度应当 ...
- vue组件的3种书写形式
第一种使用script标签 <!DOCTYPE html> <html> <body> <div id="app"> <my- ...
- CodeForces 596A
Description After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the ...