1、再讲module.exports 与exports之间的区别的时候我们先来回顾一下js里面的引用传递

   001、引用传递

   var arr = [10,20,30];
var newarr = arr; console.log(arr);//[10,20,30]
console.log(newarr);//[10,20,30]; newarr[0] = 40;
console.log(arr);//[40,20,30];
console.log(newarr);//[40,20,30];
分析:
    第一次定义var arr = [10,20,30]; 我们知道引用数据类型的数据放在堆中,索引放在栈中,索引指向的地址是堆中的地址,而var newarr = arr;是将arr的指向复制了一份给了newarr,因此第一次输出2个的值是一样的。而第二次newarr[0] = 40,因为newarr的指向和arr的指向是相同的,因此newarr[0] = 40,是将地址中的第一个数据发送了改变。而恰好两者的指向是相同的因此arr的数据也发生了改变
 
2、module.exports && exports
其实两者的关系跟上面的关系是一样的。exports是module.exports的一个引用。
    区别:
        1、module.exports默认的初始值是一个空的对象
 
        2、exports是module.exports的一个引用
 
    3、require返回的是module.exports而不是exports

【node】------module.exports&&exports之间的区别------【巷子】的更多相关文章

  1. node (02 CommonJs 和 Nodejs 中自定义模块)顺便讲讲module.exports和exports的区别 dependencies 与 devDependencies 之间的区别

    CommonJS 规范的提出,主要是为了弥补当前 JavaScript 没有标准的缺陷.它的终极目标就是:提供一个类似 Python,Ruby 和 Java 语言的标准库,而不只是停留在小脚本程序的阶 ...

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

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

  3. node——module.exports

    module.exports 1. 在a.js中 var b=require('./b.js'); console.log(b); 在b.js中 function add(x,y){ return x ...

  4. 理解node模块的exports和module.exports

    exports是module.exports的引用,即var exports = module.exports.在一个模块的开头,这两个值都指向同一个空对象:exports = module.expo ...

  5. Node.js之exports与module.exports

    每一个node.js执行文件,都自动创建一个module对象,同时,module对象会创建一个叫exports的属性,初始化的值是 {} module.exports = {}; Node.js为了方 ...

  6. node.js module.exports & exports & module.export all in one

    node.js module.exports & exports & module.export all in one cjs const log = console.log; log ...

  7. Node.js & module.exports & exports

    Node.js & module.exports & exports https://www.cnblogs.com/xgqfrms/p/9493550.html exports &a ...

  8. node基础 npm、module、exports、require

    module 模块.包:可以认为是一个代码包,package,提供特定的功能(暴露给外界接口,让外界调用) exports 输出.导出:导出模块中的各种类型的变量,以及各种方法,导出之后,才可以被外界 ...

  9. node.js中module.export与export的区别。

    对module.exports和exports的一些理解 可能是有史以来最简单通俗易懂的有关Module.exports和exports区别的文章了. exports = module.exports ...

随机推荐

  1. spring复习 -day1:Spring简介 、 Spring容器 、 Spring IOC

    Spring创建对象方法   创建对象过程: 第一步:添加SpringIOC环境 (1)在WebRoot/WEB-INT/lib文件夹下,引入SpringIOC配置环境的jar包 如图: (2)在sr ...

  2. matlab中常用见的小知识点

    矩阵相关: 在matlab中,矩阵或向量是 column-major 表示形式.用 [] 来构建向量或矩阵, 用()来引用向量或矩阵中的元素:用:表示矩阵中的该index下的所以元素: matlab中 ...

  3. 详解JNDI的lookup资源引用 java:/comp/env

    ENC的概念:     The application component environment is referred to as the ENC, the enterprise naming c ...

  4. e659. 缩放,剪取,移动,翻转图形

    AffineTransform tx = new AffineTransform(); tx.scale(scalex, scaley); tx.shear(shiftx, shifty); tx.t ...

  5. 如果不得已需要全局变量,则使全局变量加前缀 g_(表示 global)

    如果不得已需要全局变量,则使全局变量加前缀 g_(表示 global). 例如: int g_howManyPeople; // 全局变量 int g_howMuchMoney; // 全局变量 #i ...

  6. C++多线程环境下注意共享资源的释放顺序

    比如我现在写一个多线程下载程序,包含DownloadTask.HttpDownload两个类. class DownloadTask { //省略n行代码 public: int m_threads; ...

  7. js for form

    //表单填充   表单填充        , formDataLoad: function (domId, obj) {            for (var property in obj) {  ...

  8. PHP清除HTML代码、空格、回车换行符的函数

    清除HTML代码.空格.回车换行符的函数如下 function DeleteHtml($str) { $str = trim($str); $str = strip_tags($str,"& ...

  9. Cocos2d-x 3.0 Lua编程 之 响应Android手机的按键

    演示样例代码例如以下所看到的: local listenerKey= cc.EventListenerKeyboard:create() local function onKeyReleaseed(k ...

  10. POJ 3093 Margaritas(Kind of wine) on the River Walk (背包方案统计)

    题目 Description One of the more popular activities in San Antonio is to enjoy margaritas in the park ...