export, export default, import, module.exports, require

 

ES6 规范:export 和 import 配对
import 的 {} 大括号里面指定要从其他模块导入的变量名,
如果 export 命令没有写 default,那么 import {} 大括号里面的变量名,必须与 export 导出的名称相同。

 

export default 为模块指定默认输出,这样在引入时就不必关心模块输出的名字。
本质上,export default 就是输出一个叫做 default 的变量或方法,然后系统允许你为它取任意名字。

 

CommonJS 规范: module.exports 和 require 配对
Node 的模块输出和引入的方式与ESM不同,Node 采用的是 CommonJS 模块规范。
CommonJS 规范规定,在每个模块内部,module 变量代表当前模块。这个变量是一个对象,它的 exports 属性(module.exports)是对外的接口。

 

Link: https://www.cnblogs.com/farwish/p/18071697

posted on 2024-03-13 22:22  ercom  阅读(2)  评论(0编辑  收藏  举报