当前位置:网站首页>[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
2022-07-07 04:43:00 【Concise200】
import and require
I did a problem when I did the pen test today , As shown in the figure
The correct answer is as follows :
According to the online statement, it is correct , because require Import is similar to shallow copy ( If there is a shallow copy of the North nose , You can see Yiwen teaches you to distinguish assignment 、 Shallow copy and deep copy )
But the Internet also says
require adopt module.exports The exported value can no longer change ,import adopt export The exported value can be changed ;
Is it true ???
A wave of shallow practice
// a.js
let a = 1
let b = {
}
setTimeout(() => {
a = 2
b.b = 2
}, 100)
export default{
a,
b
}
import a from './a.js'
console.log(a.a)
console.log(a.b)
setTimeout(() => {
console.log(a.a)
console.log(a.b)
}, 500)
According to the online results , The answer should be
1
{}
2
{ b: 2 }
But in fact
In the above performance , Both are similar Shallow copy The operation of , It is not the same as what is said on the Internet a Will become 2.
However, if on-demand import is adopted , The basic data type and reference data type change together
let a = 1
let b = {
}
setTimeout(() => {
a = 2
b.b = 2
}, 100)
export{
a,
b
}
// Or write like this
/*export let a = 1 export let b = {} setTimeout(() => { a = 2 b.b = 2 }, 100)*/
import {
a,b} from './a.js'
console.log(a)
console.log(b)
setTimeout(() => {
console.log(a)
console.log(b)
}, 500)
The result is shown in the figure
summary :
- The default is derived and require It's all shallow copies
- On demand export is quote , Whether basic data type or reference type , as long as
Exporter
Change ,Import side
Will change .
边栏推荐
- 英特尔David Tuhy:英特尔傲腾技术成功的原因
- Win11截图键无法使用怎么办?Win11截图键无法使用的解决方法
- SQL where multiple field filtering
- ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
- Both primary and secondary equipment numbers are 0
- Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
- Vscode 如何使用内置浏览器?
- 微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
- Introduction to namespace Basics
- In cooperation with the research team of the clinical trial center of the University of Hong Kong and Hong Kong Gangyi hospital, Kexing launched the clinical trial of Omicron specific inactivated vacc
猜你喜欢
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
AI landing new question type RPA + AI =?
kivy教程之设置窗体大小和背景(教程含源码)
Video fusion cloud platform easycvr video Plaza left column list style optimization
See Gardenia minor
Windows are not cheap things
[on automation experience] the growth path of automated testing
EasyCVR视频广场点击播放时,主菜单高亮效果消失问题的修复
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
C # use Siemens S7 protocol to read and write PLC DB block
随机推荐
Some understandings about 01 backpacker
日常工作中程序员最讨厌哪些工作事项?
C # use Siemens S7 protocol to read and write PLC DB block
JS form get form & get form elements
Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
Is there any way to bookmark the code in the visual studio project- Is there a way to bookmark code in a Visual Studio project?
Ssm+jsp realizes the warehouse management system, and the interface is called an elegant interface
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
Code source de la fonction [analogique numérique] MATLAB allcycles () (non disponible avant 2021a)
MySQL forgot how to change the password
一度辍学的数学差生,获得今年菲尔兹奖
【數模】Matlab allcycles()函數的源代碼(2021a之前版本沒有)
In cooperation with the research team of the clinical trial center of the University of Hong Kong and Hong Kong Gangyi hospital, Kexing launched the clinical trial of Omicron specific inactivated vacc
The root file system of buildreoot prompts "depmod:applt not found"
视频融合云平台EasyCVR视频广场左侧栏列表样式优化
ACL2022 | 分解的元学习小样本命名实体识别
Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
Digital chemical plants realize the coexistence of advantages of high quality, low cost and fast efficiency