当前位置:网站首页>[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 .
边栏推荐
- The root file system of buildreoot prompts "depmod:applt not found"
- Both primary and secondary equipment numbers are 0
- Poor math students who once dropped out of school won the fields award this year
- What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
- Comment les tests de logiciels sont - ils effectués sur le site Web? Testez la stratégie!
- The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly
- C # use Siemens S7 protocol to read and write PLC DB block
- 视频融合云平台EasyCVR视频广场左侧栏列表样式优化
- Practice Guide for interface automation testing (middle): what are the interface testing scenarios
- MySQL split method usage
猜你喜欢
What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
EasyCVR集群版本添加RTSP设备提示服务器ID错误,该如何解决?
数学分析_笔记_第10章:含参变量积分
窗口可不是什么便宜的东西
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
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
Common methods of list and map
[multi threading exercise] write a multi threading example of the producer consumer model.
EasyCVR视频广场点击播放时,主菜单高亮效果消失问题的修复
Ssm+jsp realizes the warehouse management system, and the interface is called an elegant interface
随机推荐
Win11 control panel shortcut key win11 multiple methods to open the control panel
EasyCVR无法使用WebRTC进行播放,该如何解决?
ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战
Introduction to the PureMVC series
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
A picture to understand! Why did the school teach you coding but still not
Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
这项15年前的「超前」技术设计,让CPU在AI推理中大放光彩
acwing 843. n-皇后问题
A series of shortcut keys for jetbrain pychar
过气光刻机也不能卖给中国!美国无理施压荷兰ASML,国产芯片再遭打压
Win11控制面板快捷键 Win11打开控制面板的多种方法
Oracle -- 视图与序列
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
英特尔与信步科技共同打造机器视觉开发套件,协力推动工业智能化转型
Vscode 如何使用内置浏览器?
Win11图片打不开怎么办?Win11无法打开图片的修复方法