ES6模块与CommonJS模块有什么异同

100 阅读1分钟

ES6模块与CommonJS模块有什么异同?

CommonJS 是社区规范, ES6 Module 是官方后出的规范

  1. CommonJS 模块输出的是一个值的拷贝,ES6 Module 输出的是值的引用
  2. CommonJS 模块是运行时加载,ES6 Module 是编译时输出接口。
  3. CommonJS 是单个值导出,ES6 Module可以导出多个
  4. CommonJS 是动态语法可以写在判断里,ES6 Module 静态语法只能写在顶层
  5. CommonJS 的 this 是当前模块,ES6 Module 的 this 是 undefine