modular
Basic rules or characteristics of modularity in ES6:
1: Each module is loaded only once, and each JS is executed only once. If the same file in the same directory is loaded next time, it will be read directly from the memory. A module is a singleton, or an object;
2: The variables declared in each module are local variables and will not pollute the global scope;
3: The variables or functions inside the module can be exported through export;
4: A module can import other modules
1. Import and export
1. Export
import:
result:
2. Take only what you need
result:
3. When there are too many exports (no one-to-one correspondence)
* stands for all content, as stands for alias
result:
4. Recommended writing
result:
Advantages: 1. Some irrelevant variables will not be exported due to misoperation 2. Through export default, there is no need to know its name when it is referenced by a third party, which is more concise