当前位置:网站首页>ES6 modularization
ES6 modularization
2022-07-04 14:43:00 【Dreamy light_ dream】
List of articles
1.node.js How to realize modular specification in
node.js Followed CommonJS Modular specification of .
Import other modules to use require() Method .
Modules are shared externally as module.exports object .
2. The benefits of modularity
Everyone follows the same modular specification to write code , Reduce the cost of communication , It's very convenient for each module to call each other .
3. Classification of front-end modular specifications
stay es6 Before modularity was born ,JavaScript Community is used AMD、CMD、CommonJS Isomodular specification .
AMD、CMD Suitable for browser side .
CommonJS Applicable to server side .
Most modular specifications increase the difficulty of learning and the cost of development for developers . therefore ,es6 The module specification was born .
4.es6 Modular specification : It is a general modular development standard for browser and server .
es6 It is defined in the modular specification :
Every js File is a separate module .
Import other module members to use import keyword .
Shared module members use export keyword .
stay node.js Chinese support CommonJS Modular specification , If you want to be based on node.js Study es6 Modular Syntax , You can configure it in the following two steps :
stay package.json Add... To the root node of ”type”:”module” node .
Quickly initialize a package management configuration file -package.json The order of :
npm init -y
Commands can be carried out at the code terminal , If there are questions , Environment variables can be configured .
5.es6 The basic syntax of modularity : Yes 3 Grammar .
Default export and default import
Default export Syntax :export default { Default exported members ( Variables or functions ) }
matters needing attention : Use only once in each module export default, Otherwise, an error will be reported .
Default import Syntax :import Accept name from ‘ Module identifier ’
Example :import m1 from ./out.js
matters needing attention : Accept the name as long as it is legal .
matters needing attention : When the terminal writes a command , If appear module Problems that can't be found , Then it depends on whether there is a problem with the path .
cd Path address → You can switch paths
cls → eliminate
On demand export and on demand import
Export syntax on demand :export Members exported on demand
Import grammar on demand :import { s1 } from ‘ Module identifier ’
matters needing attention : If there are multiple member variables , Just separate them with commas .
Multiple on-demand exports can be used in each module .
The name of on-demand import is consistent with that of on-demand Export .
On demand import , have access to as Keyword to rename .
On demand import can be used with default Export .
Directly import and execute the code in the module
grammar :import ‘./direct-run.js’
边栏推荐
- LVGL 8.2 Draw label with gradient color
- 尊重他人的行为
- [information retrieval] experiment of classification and clustering
- 为什么国产手机用户换下一部手机时,都选择了iPhone?
- 韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
- Ali was laid off employees, looking for a job n day, headhunters came bad news
- Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
- Codeforce:c. sum of substrings
- Real time data warehouse
- MySQL triggers
猜你喜欢
5G电视难成竞争优势,视频资源成中国广电最后武器
Data Lake (13): spark and iceberg integrate DDL operations
Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
Xcode abnormal pictures cause IPA packet size problems
LVGL 8.2 Draw label with gradient color
Nowcoder reverse linked list
各大主流编程语言性能PK,结果出乎意料
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
Codeforce:c. sum of substrings
随机推荐
Popular framework: the use of glide
Sqlserver functions, creation and use of stored procedures
为什么国产手机用户换下一部手机时,都选择了iPhone?
LVGL 8.2 Sorting a List using up and down buttons
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
LVGL 8.2 Draw label with gradient color
Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
【C语言】指针笔试题
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
C language small commodity management system
毕业季-个人总结
LVGL 8.2 Line wrap, recoloring and scrolling
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
Leetcode t49: grouping of alphabetic words
Some problems and ideas of data embedding point
关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
Codeforce:c. sum of substrings
Ranking list of databases in July: mongodb and Oracle scores fell the most
Data center concept