commonjs circular dependency, esm circular dependency, whether the export value can be modified, how to avoid being modified

reference

commonjs

Summary: require a file is to execute the file synchronously. After the file is executed, the file export value will be cached. When accessing it again next time, you only need to take out the cache, and there is no need to execute the file twice.

insert image description here
insert image description here
insert image description here
insert image description here

esm

esm exports the memory address, when other files are imported, it will point to the same address

insert image description here
insert image description here

export value can be modified

insert image description here
insert image description here

How to avoid being modified

  1. If it's just one layer of objects, then useinsert image description here
  2. If there are nested objects, each object needs to be recursively Object.freeze

Guess you like

Origin blog.csdn.net/formylovetm/article/details/127214181