当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results

深度学习 神经网络基础

最近公共祖先(LCA)在线做法

朋友圈社区程序源码分享

PMP与NPDP之间的区别是什么?

新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码

leetcode刷题:二叉树01(二叉树的前序遍历)

Importance of EDA tools to chip industry knowledge popularization

Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers

关联线探究,如何连接流程图的两个节点
随机推荐
打出三位数的所有水仙花数「建议收藏」
个人炒股怎样开户?安全吗。
三菱PLC FX3U脉冲轴点动功能块(MC_Jog)
Common components of flask
4. 对象映射 - Mapping.Mapstercover
【级联分类器训练参数】Training Haar Cascades
最近公共祖先(LCA)在线做法
2022安全员-A证考题及在线模拟考试
Customize the insertion of page labels and realize the initial search of similar address books
Architect graduation summary
【STM32】STM32CubeMX教程二–基本使用(新建工程点亮LED灯)
Internship: gradually moving towards project development
从20s优化到500ms,我用了这三招
杰理之蓝牙耳机品控和生产技巧【篇】
人才近悦远来,望城区夯实“强省会”智力底座
Importance of EDA tools to chip industry knowledge popularization
游览器打开摄像头案例
Flume面试题
Data analysts sound tall? Understand these points before you decide whether to transform
Accelera Systems Initiative是一个独立的非营利组织