ES6 (Module modular)

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325080641&siteId=291194637