当前位置:网站首页>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 .
边栏推荐
- leetcode刷题:栈与队列06(前 K 个高频元素)
- Practical project notes (I) -- creation of virtual machine
- 一次调试去了解redis集群的slot机制
- Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
- 《軟件工程導論(第六版)》 張海藩 複習筆記
- 十三届蓝桥杯B组国赛
- 功利点没啥!
- burpsuite简单抓包教程[通俗易懂]
- 网上开户是安全的吗?新手可以开炒股账户吗。
- 联想电脑怎么连接蓝牙耳机?
猜你喜欢
随机推荐
leetcode刷题:二叉树01(二叉树的前序遍历)
《软件工程导论(第六版)》 张海藩 复习笔记
Common components of flask
Internship: complex JSON format data compilation interface
十三届蓝桥杯B组国赛
宅男壁纸大全微信小程序源码-带动态壁纸支持多种流量主
Flume面试题
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
Kuberntes云原生实战一 高可用部署架构
图片拼图微信小程序源码_支持多模板制作和流量主
pytest合集(2)— pytest运行方式
PWN攻防世界cgpwn2
C中main函数的几种写法
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
喜马拉雅自研网关架构演进过程
Past and present life of product modular design
EMC-电路保护器件-防浪涌及冲击电流用
Spark面试题
朋友圈社区程序源码分享
MQ学习笔记









