当前位置:网站首页>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 61: rotating linked list
- Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
- Red envelope activity design in e-commerce system
- ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
- leetcode:6109. Number of people who know the secret [definition of DP]
- 如何配和弦
- C language set operation
- Xcode abnormal pictures cause IPA packet size problems
- ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
猜你喜欢

The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese

Leetcode 61: rotating linked list

Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design

Why do domestic mobile phone users choose iPhone when changing a mobile phone?

STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于GPIO)

潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)

数据湖(十三):Spark与Iceberg整合DDL操作

LVGL 8.2 Draw label with gradient color

Explain of SQL optimization

Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
随机推荐
架构方面的进步
An overview of 2D human posture estimation
leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
Chapter 16 string localization and message Dictionary (2)
LVGL 8.2 keyboard
Digi重启XBee-Pro S2C生产,有些差别需要注意
LVGL 8.2 Menu
利用Shap值进行异常值检测
LVGL 8.2 Line wrap, recoloring and scrolling
Docker compose public network deployment redis sentinel mode
First experience of ViewModel
(1)性能调优的标准和做好调优的正确姿势-有性能问题,上HeapDump性能社区!
[MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
C language programming
炒股网上开户安全吗?会不会被骗。
深度学习7 Transformer系列实例分割Mask2Former
remount of the / superblock failed: Permission denied
Leetcode t47: full arrangement II