当前位置:网站首页>Difference and use between require and import
Difference and use between require and import
2022-07-01 21:36:00 【Summer thought】
、require And import The difference and use of (CommonJS Normative and es6 standard )
1、import yes ES6 The Syntax Standard in is also used to load module files ,import Function can read and execute a JavaScript file , Then return to the export Command specifies the output code .export And export default Can be used to export constants 、 function 、 file 、 modular ,export There can be multiple ,export default There can only be one .
2、require Define modules :module Variable represents the current module , its exports Property is an external interface . adopt exports Modules can be exported from modules , Loading this module from other files is actually reading module.exports Variable , They can be variables 、 function 、 Object etc. . stay node If you use exports The system will help you convert to module.exports Of , Only the export name needs to be defined for export .
require And import The difference between
1,require yes CommonJS Standardized modular syntax ,import yes ECMAScript 6 Standardized modular syntax ;
2,require Is runtime load ,import It is loaded at compile time ;
3,require It can be written anywhere in the code ,import It can only be written at the top of the file and cannot be used in conditional statements or function scopes ;
4,require adopt module.exports The exported value can no longer change ,import adopt export The exported value can be changed ;
5;require adopt module.exports Exported is exports object ,import adopt export Export is the code that specifies the output ;
6,require The properties of the module are introduced at runtime, so the performance is relatively low ,import The properties of the module are introduced during compilation, so the performance is slightly higher .
边栏推荐
- Detailed explanation and code example of affinity propagation clustering calculation formula based on graph
- 架构师毕业总结
- 人才近悦远来,望城区夯实“强省会”智力底座
- 个人炒股怎样开户?安全吗。
- 多个张量与多个卷积核做卷积运算的输出结果
- 基础—io密集型计算和cpu密集型计算
- 考虑关系的图卷积神经网络R-GCN的一些理解以及DGL官方代码的一些讲解
- 新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码
- Practical project notes (I) -- creation of virtual machine
- 联想电脑怎么连接蓝牙耳机?
猜你喜欢
随机推荐
编译原理复习笔记
【级联分类器训练参数】Training Haar Cascades
Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
How to create a pyramid with openmesh
Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)
CNN卷积神经网络原理讲解+图片识别应用(附源码)[通俗易懂]
Slf4j打印异常的堆栈信息
升级版手机检测微信工具小程序源码-支持多种流量主模式
《軟件工程導論(第六版)》 張海藩 複習筆記
Is it safe to open an account online? Can a novice open a stock trading account.
burpsuite简单抓包教程[通俗易懂]
朋友圈社区程序源码分享
String类型转换BigDecimal、Date类型
PCB线路板塞孔工艺的那些事儿~
选择在同花顺上炒股开户可以吗?安全吗?
leetcode刷题:栈与队列05(逆波兰表达式求值)
深度学习 常见的损失函数
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
Using qeventloop to realize synchronous waiting for the return of slot function
MQ学习笔记