当前位置:网站首页>1-5 nodejs commonjs specification
1-5 nodejs commonjs specification
2022-04-23 16:58:00 【Endless cake】
CommonJs standard
node Based on CommonJs Standardized design , therefore node Is the composition of the module
Built-in module :node Born to provide js Transfer
Three party modules : Someone else wrote , We can base it on npm Install and use
Custom module : Create your own modules
CommonJS The idea of modular design (AMD/CMD/ES6 module) It's all modular design ideas
1.CommonJS Regulations , every last JS It's all a single module ( Modules are private : The values and functions involved 、 Variables are private , And others JS The contents of the document are not in conflict )
2.CommonJS Allow methods in modules to call each other
B Module to call A Module method
A The module needs to be exported
CommonJS Give each module ( Every js) Built in variables are set in 、 attribute 、 Method
module: Represents the current module object
module.exports: This of the module “ attribute ” It is used to export the properties and methods of the module
exports: It's a built-in “ Variable ”, It is also used to export the properties and methods of the current module , Although and module.exports This is a thing , But the corresponding value is the same (module.exports = export) Values are objects
B Module needs to be imported
require:CommonJS Built in variables provided , Used to import modules ( In fact, import is module.exports Exposed things ), Imported values are also (object type ) Of .
require It's a synchronous operation , It will be A Modules are executed from top to bottom , hold exports The corresponding heap memory is imported , So the result is an object .
CommonJs characteristic
1. All code runs within the scope of the module , Does not contaminate the global scope ( Every module is private , Everything in it is also private , No interference with other modules )
2. Modules can be loaded multiple times , But the command runs once on the first load , Then the run results are cached , Load later , Just read the cache results directly . To make the module run at a time , You must be clear about caching .
3. The order in which the modules are loaded , In the order it appears in the code
4.CommonJS The specification loading module is synchronous , in other words , Only load complete , To perform the following operations .
版权声明
本文为[Endless cake]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230554520174.html
边栏推荐
- Pseudo Distributed installation spark
- Tencent resolves the address according to the IP address
- PyTorch:train模式与eval模式的那些坑
- 计组 | 【七 输入/输出系统】知识点与例题
- New keyword learning and summary
- Paging SQL
- 文件操作《二》(5000字总结篇)
- Camtasia2022软件新增功能介绍
- Use case execution of robot framework
- Introduction to new functions of camtasia2022 software
猜你喜欢
Sub database and sub table & shardingsphere
Pytorch: the pit between train mode and eval mode
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
Easyexcel reads the geographical location data in the excel table and sorts them according to Chinese pinyin
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
∑GL-透视投影矩阵的推导
Smart doc + Torna generate interface document
ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation
昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
面试百分百问到的进程,你究竟了解多少
随机推荐
正则过滤内网地址和网段
织梦DEDECMS安全设置指南
Paging the list collection
How vscode compares the similarities and differences between two files
Node access to Alipay open platform sandbox to achieve payment function
Expression "func" tSource, object "to expression" func "tSource, object" []
Zhongang Mining: Fluorite Flotation Process
English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
Installing labellmg tutorial in Windows
File upload and download of robot framework
Nifi fast installation and file synchronization
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
Log4j output log information to file
Blue Bridge Cup provincial road 06 -- the second game of the 12th provincial competition
MySQL master-slave configuration under CentOS
RTKLIB 2.4.3源码笔记
∑GL-透视投影矩阵的推导
博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
信息摘要、数字签名、数字证书、对称加密与非对称加密详解
AIOT产业技术全景结构-数字化架构设计(8)