In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "what are the differences between commonjs and es6 modularization", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "what are the differences between commonjs and es6 modularization" this article.
Differences: 1, the CommonJS module is loaded at run time, while the ES6 module is the compile-time output interface; 2, the require () of the CommonJS module is the synchronous loading module, while the import command of the ES6 module is asynchronous loading; 3. CommonJS is the shallow copy of the module, and ES6 is the introduction of the module.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
CommonJS
For basic data types, it belongs to replication. Will be cached by the module. At the same time, the variables output by the module can be re-assigned in another module.
For complex data types, it is a shallow copy. Because the objects referenced by the two modules point to the same memory space, changes to the value of that module affect the other module.
When a module is loaded with the require command, the code for the entire module is run.
When the same module is loaded with the require command, the module is no longer executed, but the value in the cache is fetched. That is, no matter how many times the CommonJS module is loaded, it will only run once when it is first loaded, and then it will return the result of the first run, unless the system cache is manually cleared.
When loading circularly, it is executed at load time. That is, when the script code is in require, it will all be executed. Once a module is "looped", only the parts that have been executed will be output, and the parts that have not yet been executed will not be output.
ES6 module
The values in the ES6 module belong to dynamic read-only references.
For read-only, that is, it is not allowed to modify the value of incoming variables, import's variables are read-only, regardless of basic or complex data types. When the module encounters the import command, it generates a read-only reference. Wait until the script is actually executed, and then according to this read-only reference, go to the loaded module to get the value.
For dynamic, the original value changes, and so does the value loaded by import. Whether it is a basic or complex data type.
When loading a loop, the ES6 module is a dynamic reference. The code can be executed as long as there is a reference between the two modules.
The difference between ES6 Module and CommonJS Module
The 1.CommonJS module is loaded at run time, and the ES6 module is the compile-time output interface.
The require () of the 2.CommonJS module is the synchronous loading module, and the import command of the ES6 module is loaded asynchronously, with an independent module dependent parsing phase.
3.CommonJS is a shallow copy of the module, ES6 Module is the introduction of the module, that is, ES6 Module only read-only, can not change its value, specifically, the pointer can not be changed, similar to const.
The interface of 4.import is read-only (read-only state), and its variable value cannot be modified. That is, the pointer to the variable cannot be modified, but the pointer to the variable can be changed. You can reassign the commonJS pair (change the pointer), but assigning to ES6 Module will result in a compilation error.
What ES6 modules and CommonJS modules have in common:
Both 1.CommonJS and ES6 Module can assign values to the referenced object, that is, to change the value of the object's internal properties.
These are all the contents of this article entitled "what are the differences between commonjs and es6 modularization". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.