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. excel导入导出

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using FS.Exten ...

  2. hdu4497 GCD and LCM ——素数分解+计数

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4497 如果G%L != 0,说明一定无解. 把K = G / L质数分解,G / L = p1^t1 ...

  3. hdu2191 悼念512汶川大地震 ——多重背包

    link:http://acm.hdu.edu.cn/showproblem.php?pid=2191 最简单的那种 #include <iostream> #include <cs ...

  4. rtabmap_ros安装---43

    摘要: 原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 一.前言 RTAB-Map (Real-Time Appearance-Based Mappin ...

  5. input:-webkit-autofill 导致chrome的输入框背景颜色变成黄色

    填写form表单时发现chrome的一个好坑啊! 当你之前有填写过表单,获取焦点时,input会有一个记录之前填写过的文本的下拉列表式的东东,就像这样:(抱歉丑了点,隐私问题打上了马赛克) 按理说,这 ...

  6. Win8 WinRT将替换Win32 API程序员何去何从?

    win8 新引入了称为WinRT的核心API.支持使用C/C++..NET或JavaScript来开发Metro风格的应用.这些应用自动获得硬件加速和高级电源管理的功能.现有的Silverlight和 ...

  7. BizTalk 中使用 WCF-OracleDB adapter

    在使用BizTalk WCF-OracleDB adapter操作Oracle数据库时,遇到了一些问题,记录如下. 按照BizTalk的文档,目前BizTalk 2010支持的Oracle数据库版本如 ...

  8. shiro 标签

    在使用Shiro标签库前,首先需要在JSP引入shiro标签: <%@ taglib prefix="shiro" uri="http://shiro.apache ...

  9. Oracle导入和导出

    导出:EXP userid=<username>/<password>@<service_name> file=<dmpname> e.g.exp sa ...

  10. JavaScript 数据验证类

    JavaScript 数据验证类 /* JavaScript:验证类 author:杨波 date:20160323 1.用户名验证 2.密码验证 3.重复密码验证 4.邮箱验证 5.手机号验证 6. ...