1, writing
CommonJs: require + module.exports
ES6: import + export / export default
2. Execution timing
CommonJs: runtime
ES6: compile time. At compile time, you can determine module dependencies, as well as input and output variables. Objective: Static optimization
- Static parsing, such as typeScript
- Loading import {getCache, setCache} from ‘cache’ on demand only packages the two modules used
3, output,
CommonJs: copy of the value. Cache after loading, cache after the first time
ES6: References to values. Changes to the called module will affect where the call is made