当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
目標檢測——Yolo系列
多个张量与多个卷积核做卷积运算的输出结果
【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
EMC-电路保护器件-防浪涌及冲击电流用
杰理之蓝牙耳机品控和生产技巧【篇】
【级联分类器训练参数】Training Haar Cascades
Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)
Data analysts sound tall? Understand these points before you decide whether to transform
leetcode刷题:栈与队列03(有效的括号)
Learn white box test case design from simple to deep
2022安全员-A证考题及在线模拟考试
BPR(贝叶斯个性化排序)
【STM32】STM32CubeMX教程二–基本使用(新建工程点亮LED灯)
Practical project notes (I) -- creation of virtual machine
股票手机开户哪个app好,安全性较高的
CNN卷积神经网络原理讲解+图片识别应用(附源码)[通俗易懂]
小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
三菱PLC FX3U脉冲轴点动功能块(MC_Jog)
深度学习 神经网络基础
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan