当前位置:网站首页>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刷题:二叉树03(二叉树的后序遍历)
- cmake工程化相关
- 测试撤销1
- 【级联分类器训练参数】Training Haar Cascades
- 功利点没啥!
- Customize the insertion of page labels and realize the initial search of similar address books
- 强大的万年历微信小程序源码-支持多做流量主模式
- CNN卷积神经网络原理讲解+图片识别应用(附源码)[通俗易懂]
- 【mysql 07】GPG key retrieval failed: “Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022“
- Kuberntes云原生实战一 高可用部署架构
猜你喜欢

leetcode刷题:栈与队列07(滑动窗口最大值)

最近公共祖先离线做法(tarjan)

《软件工程导论(第六版)》 张海藩 复习笔记

Penetration tools - trustedsec's penetration testing framework (PTF)

Test of NSI script

天气预报小程序源码 天气类微信小程序源码

NSI脚本的测试

以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌

8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide

杰理之烧录都使用 VBAT 供电,供电电压 4.2V【篇】
随机推荐
芭比Q了!新上架的游戏APP,咋分析?
NSI脚本的测试
leetcode刷题:栈与队列03(有效的括号)
关联线探究,如何连接流程图的两个节点
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
三菱PLC FX3U脉冲轴点动功能块(MC_Jog)
深度学习 神经网络基础
小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
手动实现function isInstanceOf(child,Parent)
MQ学习笔记
On the usage of a magic function
PCB线路板塞孔工艺的那些事儿~
leetcode刷题:二叉树01(二叉树的前序遍历)
300 linear algebra Lecture 4 linear equations
burpsuite简单抓包教程[通俗易懂]
天气预报小程序源码 天气类微信小程序源码
NIO与传统IO的区别
Learn white box test case design from simple to deep
分离字符串中的字母和数字并使得字母在前数组在后
4. 对象映射 - Mapping.Mapstercover