当前位置:网站首页>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 .
边栏推荐
- js数组拼接的四种方法[通俗易懂]
- 浏览器tab页之间的通信
- Customize the insertion of page labels and realize the initial search of similar address books
- 目标检测——Yolo系列
- Spark面试题
- Target detection - Yolo series
- Penetration tools - trustedsec's penetration testing framework (PTF)
- leetcode刷题:栈与队列05(逆波兰表达式求值)
- Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
- 分离字符串中的字母和数字并使得字母在前数组在后
猜你喜欢
随机推荐
【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
PCB线路板塞孔工艺的那些事儿~
Common components of flask
在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
300 linear algebra Lecture 4 linear equations
东哥套现,大佬隐退?
String类型转换BigDecimal、Date类型
Learn white box test case design from simple to deep
EMC-电路保护器件-防浪涌及冲击电流用
C中main函数的几种写法
There are four ways to write switch, you know
杰理之、产线装配环节【篇】
架构师毕业总结
基于K-means的用户画像聚类模型
Accelera Systems Initiative是一个独立的非营利组织
升级版手机检测微信工具小程序源码-支持多种流量主模式
联想电脑怎么连接蓝牙耳机?
2022安全员-A证考题及在线模拟考试
股票手机开户哪个app好,安全性较高的
新版图解网络PDF即将发布









