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. Python 基礎 - 認識模塊

    什麼是模塊?簡單說就是別人寫好了一堆功能,封裝在一起. 模塊有分二種,一個是之前有提到的 標準庫,就是不需要透過額外的安裝就有的模塊 ,另一個叫 第三方庫,需要另外安裝才能使用的模塊 #!/usr/b ...

  2. js 开启video全屏模式

    方法一: function launchFullScreen() { var element = document.documentElement; if(element.requestFullScr ...

  3. Kubuntu 使用YaH3C进行中大校园网认证

    之前都是用路由器连网线上网,我也没注意到inode校园网客户端在linux上的问题.直到前两天把路由器给搞残废了,只能默默的找办法装inode.根据学校网络中心给的教程,在kubuntu上尝试安装in ...

  4. frame和bounds区别

    学习ios开发有一段时间了,项目也做了两个了,今天看视频,突然发现view的frame和bound两个属性,发现bound怎么也想不明白,好像饶你了死胡同里,经过一番尝试和思考,终于弄明白bound的 ...

  5. ASP.NET 下拉列表绑定枚举类型值,不用再新建一个枚举表

    public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArg ...

  6. 安卓中自定义并使用Volley框架请求网络

    大家好,今天我们讲一下如何使用Volley框架请求网络,为何要使用Volley框架,这就要先说一下使用Volley框架请求网络的优点了,volley是易于定制的,即你可以根据需求来设定volley框架 ...

  7. Google 的开源技术protobuf 简介与例子

    本文来自CSDN博客:http://blog.csdn.NET/program_think/archive/2009/05/31/4229773.aspx 今天来介绍一下"Protocol  ...

  8. c语言字符串操作大全

     C语言字符串操作函数 函数名: strcpy 功  能: 拷贝一个字符串到另一个 用  法: char *stpcpy(char *destin, char *source); 程序例: #incl ...

  9. DCM TUTORIAL – AN INTRODUCTION TO ORIENTATION KINEMATICS (REV 0.1)

    原英文地址:dcm_tutorial 感觉这篇文章还是很有学习价值的,所以就抽出了一些时间对本文进行的翻译.下面这个好多人用的算法就是一种DCM 滤波器. //==================== ...

  10. windows server2012 r2 上 安装 IIS8.5

    一时间不知道怎么开头了,直接上图吧! 本人技术不高,正在学习中, 要是有 喜欢 .Net,觉得酷的,欢迎来 QQ群  316497348  交流分享!