https://cnodejs.org/topic/5231a630101e574521e45ef8

//一句话总结:exports是对module.exports的引用,require()返回的是 module.exports,
导出非对象接口时用覆盖module.exports的方法,导出对象接口时,exports 和 module.exports都行。 //module.exports 初始值为一个空对象
console.log(module.exports);//{} //exports是对module.exports的引用
console.log(exports);//所以也为{} //给module.exports添加属性方法或者修改module.exports的属性方法,exports对象也可以访问到,因为他们指向同一块内存地址,反之亦然
module.exports.name='123';
module.exports.fn=function(){
console.log(this.name)
}
module.exports.fn()//123
console.log(exports.name)//123
exports.fn()//123 exports.name='456';
exports.fn=function(){
console.log(this.name)
}
exports.fn()
console.log(module.exports.name)//456
module.exports.fn()//456 //覆盖module.exports或者exports整个对象
function aa(){
console.log('aaaaaaa')
}
module.exports=aa;//指向了新创建的对象
module.exports()//aaaaaaa
console.log(exports) //{ name: '456', fn: [Function] },还是老的地址
exports=module.exports//重新让exports指向module.exports
exports()//aaaaaaa //类似于:
var x={}
var y=x
console.log(x)//{}
console.log(y)//{}
x={'new':'new'}
console.log(y)//{}
console.log(x)//{'new':'new'} //require() 返回的是 module.exports 而不是 exports
//module.exports 写法
//aa.js
function abc(ag1){
return ag1
}
module.exports='abc' //require(aa)
var abc=require('./aa');
abc('ag1') //exports 写法
//aa.js
function abc(ag1){
return ag1
}
exports.abc=abc;//exports.abc==module.exports.abc
//require(aa)
var abc=require('./aa');//返回module.exports对象
abc.abc('ag1')//module.exports.abc

  

exports 和 module.exports 的区别的更多相关文章

  1. nodejs模块中exports和module.exports的区别

    通过Node.js的官方API可以看到Node.js本身提供了很多核心模块 http://nodejs.org/api/ ,这些核心模块被编译成二进制文件,可以require('模块名')去获取:核心 ...

  2. node exports和module.exports区别

    我们只需知道三点即可知道 exports 和 module.exports 的区别了: exports 是指向的 module.exports 的引用 module.exports 初始值为一个空对象 ...

  3. exports和module.exports的区别

    总结:exports是module.exports的指向. 1. module应该是require方法中,上下文中的对象 2. exports对象应该是上下文中引用module.exports的新对象 ...

  4. nodejs中exports与module.exports的区别详细介绍

    如果模块是一个特定的类型就用Module.exports.如果模块是一个典型的"实例化对象"就用exports. exports.name = function() { conso ...

  5. exports与module.exports的区别,export与export.defult区别

    在JS模块化编程中,之前使用的是require.js或者sea.js.随着前端工程化工具webpack的推出,使得前端js可以使用CommonJS模块标准或者使用ES6 moduel特性. 在Comm ...

  6. 【nodejs】exports 和 module.exports 的区别

    require 用来加载代码,而 exports 和 module.exports 则用来导出代码.但很多新手可能会迷惑于 exports 和 module.exports 的区别,为了更好的理解 e ...

  7. exports和module.exports区别

    参考:module.exports与exports的区别.关于exports的总结 exports 和 module.exports 的区别 module.exports是真正的模块接口,而expor ...

  8. exports与module.exports的区别

    nodejs有自己的模块系统,分为文件模块和内置模块.webpack是运行在node环境中,在学习vue-cli的webpack配置的时候, 发现有的文件模块: exports.fun1=functi ...

  9. exports与module.exports的区别,以及export与export.defult的区别

    在 JS 模块化编程的模块引入上, 主要有两种方式: CommonJS 模块标准 ES6 moduel 特性 1. CommonJS 模块引入:require() 模块导出:exports 或者 mo ...

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

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

随机推荐

  1. JSP EL表达式 与输入有关的内置对象

    与输入有关的隐含对象有两个param和paramValues,用来取得用户的请求参数.在使用EL之前可以使用如下代码取得用户的请求参数: request.getParameter(String nam ...

  2. 转 C# DataTable 和List之间相互转换的方法

    一.List/IEnumerable转换到DataTable/DataView 方法一: /// <summary> /// Convert a List{T} to a DataTabl ...

  3. [vijos P1880]ファーラの力

    据说这是一道 JOI 的题?反正我觉着挺好的喵~ 题目看起来十分可怕,但是代码还是很短的 显而易见的,ans 因分为3个部分:1.中途增加光压的时间 2.中途减少光压的时间 3. 所有路程的总时间 发 ...

  4. ajax+php处理案例

    <div> <table> <tr> <th>状态</th> <th>信息</th> </tr> < ...

  5. docvalues和Fieldcache

    Fieldcache:  docID->document->fieldvalue 无论是聚类排序关联等,首先都需要获得文档中某个字段的值,通过docID去获得整个document,然后再去 ...

  6. Python scikit-learn机器学习工具包学习笔记:feature_selection模块

    sklearn.feature_selection模块的作用是feature selection,而不是feature extraction.   Univariate feature selecti ...

  7. JTAG和SWD连接关系图

    经实际测试 SWD最少接线方法: 1.VTref与Vsupply短接 2.JLINK的SWDIO与目标板SWDIO相连 3.JLINK的SWCLK与目标板SWCLK相连 4.JLINK任意一个GND与 ...

  8. bzoj2515 Room

    Description Input Output 折半搜索,用散列表记录从原点出发,用了S(状压表示)这几种边(令|S|*2-1<=n),到达(x,y)的最大面积. #include<cs ...

  9. php接收到的json格式不标准,某个字段中的文本包含双引号的处理

    $str = '[{"Count":"1789"},{"裁判要旨段原文":"本瑶","案件类型":& ...

  10. linux下的vim使用教程

    命令历史 以:和/开头的命令都有历史纪录,可以首先键入:或/然后按上下箭头来选择某个历史命令. 启动vim 在命令行窗口中输入以下命令即可 vim 直接启动vim vim filename 打开vim ...