当前位置:网站首页>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’
边栏推荐
- 数据中台概念
- 韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
- leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
- Digi重启XBee-Pro S2C生产,有些差别需要注意
- 数据湖(十三):Spark与Iceberg整合DDL操作
- 关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
- 尊重他人的行为
- remount of the / superblock failed: Permission denied
- Abnormal value detection using shap value
- 【云原生】我怎么会和这个数据库杠上了?
猜你喜欢
flink sql-client. SH tutorial
聊聊保证线程安全的 10 个小技巧
10. (map data) offline terrain data processing (for cesium)
Programmers exposed that they took private jobs: they took more than 30 orders in 10 months, with a net income of 400000
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
leetcode:6109. Number of people who know the secret [definition of DP]
Comment configurer un accord
LVGL 8.2 LED
Query optimizer for SQL optimization
实时数据仓库
随机推荐
Leetcode T48: rotating images
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
Codeforce:c. sum of substrings
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
SqlServer函数,存储过程的创建和使用
Summary of common problems in development
Xcode abnormal pictures cause IPA packet size problems
Ali was laid off employees, looking for a job n day, headhunters came bad news
Expose Ali's salary and position level
Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
Query optimizer for SQL optimization
Programmer turns direction
Test evaluation of software testing
LVGL 8.2 text shadow
leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
C language book rental management system
LVGL 8.2 Draw label with gradient color
AI与生命科学