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. 【Avalon源码】iterator

    function iterator(vars, body, ret) { var fun = 'for(var ' + vars + 'i=0,n = this.length; i < n; i ...

  2. crontab 移动日志-超越昨天的自己系列(12)

    linux上定时执行某些脚本是管理服务器的时候比较常用的场景,比如定时检查进程是否存在,定时启动或关闭进程,定时检查日志删除日志等. 当我打开google百度crontab时长篇大论的一大堆,详细解释 ...

  3. LintCode Balanced Binary Tree

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  4. Qt之QComboBox(基本应用、代理设置)(转)

    QComboBox下拉列表比较常用,用户可以通过选择不同的选项来实现不同的操作,如何实现自己的下拉列表呢? 很多人在问QComboBox如何设置选项的高度.代理等一些问题!今天就在此分享一下自己的一些 ...

  5. MFC 中编辑框数字限制范围

    http://www.cnblogs.com/ziwuge/archive/2011/11/15/2249541.html void CSAAlt::OnEnChangeSlocp()//样本盘号输入 ...

  6. Python-select详解(select、epoll)

    select函数操作集合的时候有个要求,要么集合本身是描述符,要么他提供一个fileno()接口,返回一个描述符. I/O多路复用是在单线程模式下实现多线程的效果,实现一个多I/O并发的效果.看一个简 ...

  7. bootstrap表格内容垂直居中

    td{ vertical-align: middle !important;}

  8. JAVA监听器原理

    http://blog.csdn.net/longyulu/article/details/25054697 JAVA监听器原理 标签: 监听器 2014-05-05 15:40 9070人阅读 评论 ...

  9. Centos 安装vsftpd 服务器

    一:检查有没有安装vsftpd 二:安装vsftpd 三:安装之后重启 四:修改vsftpd配置文件 配置文件路径在/etc/vsftpd目录下 默认是注释掉的,把#号去掉 然后重启vsftpd 五: ...

  10. C#:安装Windows服务,动态指定服务名及描述

    Installer.cs>> public Installer() { InitializeComponent(); /* 服务未注册前,System.Configuration.Conf ...