当前位置:网站首页>Differences between commonjs and ES6 modularity

Differences between commonjs and ES6 modularity

2022-06-26 09:04:00 You are far from it.

  1. Briefly describe the differences

Compatibility
commonJS stay node Use in , and ES6 Module incompatibility ,ES6 compatible node And browser
grammar
commonJS yes require and module.exports
ES6 yes important and export

  1. Run time loading and compile time loading

commonJS Is runtime load , Is all the ways to load this module
ES Modules are loaded at compile time , Only load the methods you need , Cannot load methods on all modules , Efficient than commonJS higher

  1. Three major differences
  1. commonJS Output is worth copying ES6 Module output is worth quoting
  2. commonJS Is runtime load , ES6 Patterns are compile time output interfaces
  3. commonJS require() Is the synchronous load module ,ES6 Modular import The command is loaded asynchronously , There is a separate parsing phase for module dependencies
原网站

版权声明
本文为[You are far from it.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260838084214.html