在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的关系及使用的更多相关文章

  1. node.js中的exports和module.exports

    不同的编程语言都有各自的代码组织和复用的方式,如.net.php中的命名空间,python中的import,ruby中的module等,来避免命名空间污染.一直都没搞清楚node中的exports和m ...

  2. node.js模块中exports和module.exports的区别

    Node应用由模块组成,采用CommonJS模块规范. 根据这个规范,每个文件就是一个模块,有自己的作用域.在一个文件里面定义的变量.函数.类,都是私有的,对其他文件不可见. CommonJS规范规定 ...

  3. Node.js中exports与module.exports的区别

    原文:http://www.hacksparrow.com/node-js-exports-vs-module-exports.html 你肯定对Node.js模块中用来创建函数的exports对象很 ...

  4. Node.js exports与module.exports的关系

    今天搜索module.exports时看到CNode社区上发的Hack Sparrow一篇相关文章的链接 Node.js Module – exports vs module.exports 一篇5年 ...

  5. Node.js中exports,module.exports以及require方法

    在Node.js中,使用module.exports.f = ...与使用exports.f = ...是一样的,此时exports就是module.exports的一种简写方式.但是,需要注意的是, ...

  6. Node.js 中 exports 和 module.exports 的区别

    每一个模块中都有一个 module 对象, module 对象中有一个 exports 对象 我们可以把需要导出的成员都放到 module.exports 这个接口对象中,也就是 module.exp ...

  7. Node.js中的exports与module.exports的区分

    1. module应该是require方法中,上下文中的对象 2. exports对象应该是上下文中引用module.exports的新对象 3. exports.a = xxx 会将修改更新到mod ...

  8. (译)Node.js的模块-exports和module.exports

    原文标题:Node.js Module – exports vs module.exports 原文链接:http://www.hacksparrow.com/node-js-exports-vs-m ...

  9. Node.js模块导出module.exports 和 exports,Es6模块导出export 和export default的区别

    1.module.exports  module变量代表当前模块.这个变量是一个对象,module对象会创建一个叫exports的属性,这个属性的默认值是一个空的对象: module.exports ...

随机推荐

  1. 2767 Proving Equivalences 至少加几条边让全部图变成强连通模板题

    #include<stdio.h> #include<string.h> #define N 21000 struct node { int u,v,next; }bian[N ...

  2. ExtJs之Ajax模式的表单数据加载

    简单: <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-e ...

  3. WIN7通过批处理开启/禁用无线网卡

    哥比較懒,直接上步骤: 1.看自己的电脑是否有devcon.exe 这个软件,能够直接在WINDOWS文件夹的SYSTEM32文件夹下面搜索.也能够通过命令行RUN-----------CMD---- ...

  4. Android-黑科技-微信抢红包必备软件

                        黑科技微信抢红包 介绍: 本节类容和技术无太大关系.主要是个人认为比較好玩,年关将至,对于新起之秀微信红包.绝对是过春节首选.看到就是赚到,速速围观下载.眼下仅 ...

  5. 数学之路-python计算实战(4)-Lempel-Ziv压缩(2)

    Format characters have the following meaning; the conversion between C and Python values should be o ...

  6. C#替换字符串起始/结尾指定的字符串

    #region 替换字符串起始位置(开头)中指定的字符串 /// <summary> /// 替换字符串起始位置(开头)中指定的字符串 /// </summary> /// & ...

  7. C 中 main 函数的參数

          看到不同的人写出的 C 或者 C++ 程序时,可能会出现不一样的 main 函数的定义,以下的几种定义方式都是对的: int main(void) int main(int argc) i ...

  8. HDU3535 AreYouBusy 混合背包

    题目大意 给出几组物品的体积和价值,每组分为三种:0.组内物品至少选一个:1.组内物品最多选一个:2.组内物品任意选.给出背包容量,求所能得到的最大价值. 注意 仔细审题,把样例好好看完了再答题,否则 ...

  9. SVGImageView

    In essence, I'm trying to layer multiple ImageViews (one of which is a floor plan, the other a recta ...

  10. Reset and Clear Recent Items and Frequent Places in Windows 10

    https://www.tenforums.com/tutorials/3476-reset-clear-recent-items-frequent-places-windows-10-a.html ...