当前位置:网站首页>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’
边栏推荐
- leetcode:6109. 知道秘密的人数【dp的定义】
- Node mongodb installation
- 如何搭建一支搞垮公司的技术团队?
- 關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
- LVLG 8.2 circular scrolling animation of a label
- Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
- How to match chords
- Count the running time of PHP program and set the maximum running time of PHP
- C language set operation
- 5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television
猜你喜欢
Red envelope activity design in e-commerce system
Leetcode 61: rotating linked list
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
阿里被裁员工,找工作第N天,猎头又传来噩耗...
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Leetcode T48: rotating images
软件测试之测试评估
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
随机推荐
为什么国产手机用户换下一部手机时,都选择了iPhone?
现代控制理论入门+理解
LVGL 8.2 text shadow
Test evaluation of software testing
flink sql-client. SH tutorial
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
leetcode:6109. Number of people who know the secret [definition of DP]
No servers available for service: xxxx
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
MySQL triggers
ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
Is it safe to open an account online for stock speculation? Will you be cheated.
[cloud native] how can I compete with this database?
leetcode:6109. 知道秘密的人数【dp的定义】
Respect others' behavior
LVGL 8.2 Line wrap, recoloring and scrolling
C language achievement management system for middle school students
remount of the / superblock failed: Permission denied