我们只需知道三点即可知道 exports 和 module.exports 的区别了: exports 是指向的 module.exports 的引用 module.exports 初始值为一个空对象...; } 其实是对 exports 进行了覆盖,也就是说 exports 指向了一块新的内存(内容为一个计算圆面积的函数),也就是说 exports 和 module.exports 不再指向同一块内存...= module.exports 原因也很简单, module.exports = somethings 是对 module.exports 进行了覆盖,此时 module.exports 和 exports...的关系断裂,module.exports 指向了新的内存块,而 exports 还是指向原来的内存块,为了让 module.exports 和 exports 还是指向同一块内存或者说指向同一个 “对象...”,所以我们就 exports = module.exports 。
在nodejs中,提供了exports和module.exports导出模块, require对象从外部获取一个模块的,即所获取模块的 exports或者module.exports导出的模块。...module.exports和exports是属于CommonJS模块规范!根据这个规范,每个文件就是一个模块,有自己的作用域。在一个文件里面定义的变量、函数、类,都是私有的,对其他文件不可见。...这个变量是一个对象,它的exports属性(即module.exports)是对外的接口。加载某个模块,其实是加载该模块的module.exports属性。...如果你希望你的模块就想为一个特别的对象类型,请使用module.exports;如果希望模块成为一个传统的模块实例,请使用exports.xx方法;module.exports才是真正的接口,exports...最终返回给调用的是module.exports而不是exports。
刚开始的时候exports和module.exports指向同一个空对象: ? 我们可以给exports或者module.exports添加任意属性,实际上相当于作用于同一个对象。...当我们导出一个模块的时候,最终得到的实例实际是由module.exports来定义的,而不是exports。...如果没有显式定义module.exports,exports就会收集它由定义的任意属性并将它们赋予给module.exports。...如果已经显式定义了module.exports, exports中定义的对象将会被忽略。例如: module.exports = 'ROCK IT!'...也就是说,只要我们不直接覆写module.exports,那么module.exports与exports并没有任何区别。
注意,就像任何变量,如果一个新的值被赋值给exports,它就不再绑定到module.exports(其实是exports.属性会自动挂载到没有命名冲突的module.exports.属性) require...console.log(module.exports); // {} console.log(exports === module.exports); // true console.log(exports...3.module.exports和exports所指向的内存地址相同 事例二:2.js、3.js // 2.js exports.id = 'exports的id'; exports.id2 = '...exports的id2'; exports.func = function(){ console.log('exports的函数'); }; exports.func2 = function() {.../exports.上时,exports.id=1和module.exports.id=100,module.exports.id=function(){}和exports.id=function(){}
require 用来加载代码,而 exports 和 module.exports 则用来导出代码。...但很多新手可能会迷惑于 exports 和 module.exports 的区别,为了更好的理解 exports 和 module.exports 的关系,我们先来巩固下 js 的基础。...明白了上述例子后,我们只需知道三点就知道 exports 和 module.exports 的区别了: module.exports 初始值为一个空对象 {} exports 是指向的 module.exports...我们经常看到这样的写法: exports = module.exports = somethings 上面的代码等价于: module.exports = somethings exports = module.exports...原理很简单,即 module.exports 指向新的对象时,exports 断开了与 module.exports 的引用,那么通过 exports = module.exports 让 exports
module.exports和exports是属于 CommonJS 模块规范,export和export default是属于ES6语法。...这个变量是一个对象,它的exports属性(即module.exports)是对外的接口。加载某个模块,其实是加载该模块的module.exports属性。...为每个模块提供一个exports变量,指向module.exports。...var exports = module.exports; exports其实是module.exports的引用 ,可以直接在exports对象上添加相关的方法。...和exports的用法是后面加一个等号,再接具体的导出 module.exports=... exports=... (2)export和export default的用法是后面直接接具体的导出,没有等号
/user'); console.log( `${getName()} was born on ${dob}.` ); 那么,module.exports和exports的不同之处是什么?...在exports上添加一些东西: // index.js exports.foo = 'foo'; console.log(module); 输出如下: Module { id: '....', exports: { foo: 'foo' }, ... 为 exports 分配的属性也会将它们添加到 module.exports。...这是因为(至少最初)exports 是对 module.exports 的引用。 应该用哪个 由于 module.exports 和 exports 都指向同一个对象,因此使用哪个通常并不重要。...那么,请看下面的内容: exports.foo = 'foo'; module.exports = () => { console.log('bar'); }; 这样只会导出一个匿名函数。
请牢记一条原则:无论使用 exports 暴露成员,或是 module.exports 暴露成员,最终暴露的结果,都是以 module.exports 所指向的对象为准。...exports 是 node 为了简化向外共享成员的代码,提供的一个新方式,在默认情况下,exports 和 module.exports 指向的是同一个对象(为了不混淆,你可以理解为 exports...是 module.exports 对象地址的一个引用,exports 本质是一个变量) 两者没有区别,是全等的 注意: 在使用 module.exports 时,我们可以将某一个对象赋值给 module.exports...原因是因为 exports 在默认情况下是指向 module.exports 对象的引用,如果为 exports 赋值了,那么也就是说 exports 不再指向 module.exports 所指的对象的地址...重要结论:module.exports 和 exports 同指一个对象,但是最终暴露结果以 module.exports 的为准,上面的代码中,exports 改变了指向,而我们又没有为 module.exports
Module.exports才是真正的接口,exports只不过是它的一个辅助工具。 最终返回给调用的是Module.exports而不是exports。...所有的exports收集到的属性和方法,都赋值给了Module.exports。当然,这有个前提,就是Module.exports本身不具备任何属性和方法。...如果,Module.exports已经具备一些属性和方法,那么exports收集来的信息将被忽略。 如果你想你的模块是一个特定的类型就用Module.exports。...1、exports 是指向的 module.exports 的引用 2、module.exports 初始值为一个空对象 {},所以 exports 初始值也是 {} 3、require() 返回的是...module.exports 而不是 exports //exports只是一个引用!!!
typeScript:exports is not defined一、场景环境介绍:一个ts文件、一个html文件,编译ts文件为js,引入到html中出现这个错误。...二、错误原因:1、网上说法:因为ts编译为js时便意语浏览器不支持,把tsconfig.json文件的target改为es2015.2、网上说法:在html头部引入一下代码:var exports
明白了上述例子后,我们只需知道三点就知道 exports 和 module.exports 的区别了: module.exports 初始值为一个空对象 {} exports 是指向的 module.exports...的引用 require() 返回的是 module.exports 而不是 exports Node.js 官方文档的截图证实了我们的观点: ?...exports = module.exports = {...} 我们经常看到这样的写法: exports = module.exports = {...}...上面的代码等价于: module.exports = {...} exports = module.exports 原理很简单:module.exports 指向新的对象时,exports 断开了与 module.exports...的引用,那么通过 exports = module.exports 让 exports 重新指向 module.exports。
因此node.js提供了一个变量exports作为module.exports的引用 16.js也可以写成: let name = '叶文洁' // exports 是 module.exports 的引用...console.log(exports === module.exports) // true exports.name = name exports.introduce = function (name...17.js 章北海 既然exports === module.exports,那么为何修改exports不起作用?...原因是,exports是module.exports的引用,当exports被重新赋值时,并不会影响到module.exports的值,而模块返回的是module.exports,因而只有给module.exports...同一个引用 来个更复杂点的例子: 18.js let name = '章北海' module.exports = name exports = {} exports.age = 10 module.exports
对于module.exports、exports和export、export default之间的关系以及他们的区别一直处于懵逼状态的小伙伴,本篇文章带你走进新大陆。...// 通过module.exports将appid与bar暴露出去 module.exports = { appid , bar } -----------------------------...: 为了方便,Node为每个模块提供一个exports变量,指向module.exports。...let exports = module.exports; !!! 这里要注意: 不能直接将exports变量指向一个值,因为这样等于切断了exports与module.exports的联系。...let exports = module.exports let appid = '123456' // 错误写法 exports = { appid } // 正确写法 exports.appid
: 添加用户 userdel: 删除用户 passwd: 修改用户密码 groupadd: 添加用户组 groupdel: 删除用户组 软件包管理: apt 或 yum: 包管理工具(取决于Linux
Linux常用命令 Shell是运维和系统管理员操作Linux系统的首选,简单的说,它是一个命令解释器。...如:ls text[1-3] 或 ls test[a-z] 示例: ls *1 ——>test1 ls test[123] --> test1 test2 test3 Linux 下环境下有几种不同...---- man **作用:**Linux为所有命令和系统调用编写了帮助手册。使用man命令可以方便地获取某个命令的帮助信息。 **用法:**man [手册编号] 命令名,手册编号可以省略。...---- vim vim是UNIX和Linux上标配的编辑器,功能十分强大。 vim xxx 插入模式 输入字符,并可以按光标键移动输入字符位置。
require 提到 exports 和 module.exports 我们不得不提到 require 关键字。...exports 与 module.exports 区别 js文件启动时 在一个 node 执行一个文件时,会给这个文件内生成一个 exports 和 module 对象, 而module又有一个 exports...exports = module.exports = {}; 看一张图理解这里更清楚: ?...我们经常看到这样的写法: exports = module.exports = somethings 上面的代码等价于: module.exports = somethings exports = module.exports...原理很简单,即 module.exports 指向新的对象时,exports 断开了与 module.exports 的引用,那么通过 exports = module.exports 让 exports
linux目录结构: linux不像Windows 分了盘,它根目录下有如下常用文件夹: home ---------- 用户的家 root --...超级管理员root的家 etc ---------- 存放配置文件 usr ---------- 存放共享资源 常用命令...6、其他常用命令: ①、grep命令 grep category a.txt 表示在a.txt中查找category字符串所在的行,前提是打开了a.txt文件。...底行模式有如下常用命令: q 不保存退出 q! 不保存强制退出 wq 保存退出 8、管道: 管道:|,将一个命令的输出作为另一个命令的输入。
-c 创建一个新tar文件 -v 显示运行过程的信息 -f 指定文件名 -z 调用gzip命令进行压缩 -t 查看压缩文件的内容 -x 解开tar文...
一般情况下进入tomcat/bin路径下shutdown.sh关闭,再放入项目文件启动即可
Linux软件包管理 dpkg (Debian Package)管理工具,软件包名以.deb后缀。这种方法适合系统不能联网的情况下。...比如安装tree命令的安装包,先将tree.deb传到Linux系统中。再使用如下命令安装。...1.5.3-1_i386.deb 安装软件 sudo dpkg -r tree 卸载软件 注:将tree.deb传到Linux...sudo chown root:root jdk-7u21-linux-i586.tar.gz 文件权限管理 三种基本权限 R 读 数值表示为4 W ...如图所示,jdk-7u21-linux-i586.tar.gz文件的权限为-rw-rw-r-- -rw-rw-r--一共十个字符,分成四段。
领取专属 10元无门槛券
手把手带您无忧上云