当前位置:网站首页>[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 .
边栏推荐
- Unit test asp Net MVC 4 Application - unit testing asp Net MVC 4 apps thoroughly
- Easycvr cannot be played using webrtc. How to solve it?
- 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
- jvm是什么?jvm调优有哪些目的?
- Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
- See Gardenia minor
- 英特尔David Tuhy:英特尔傲腾技术成功的原因
- NTU notes 6422quiz review (1-3 sections)
- 赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
- 窗口可不是什么便宜的东西
猜你喜欢
In depth analysis of kubebuilder
图灵诞辰110周年,智能机器预言成真了吗?
[multi threading exercise] write a multi threading example of the producer consumer model.
Ssm+jsp realizes the warehouse management system, and the interface is called an elegant interface
测试/开发程序员怎么升职?从无到有,从薄变厚.......
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
Digital chemical plant management system based on Virtual Simulation Technology
How do test / development programmers get promoted? From nothing, from thin to thick
Basic idea of counting and sorting
namespace基础介绍
随机推荐
【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
Lecture 3 of "prime mover x cloud native positive sounding, cost reduction and efficiency enhancement lecture" - kubernetes cluster utilization improvement practice
MySQL forgot how to change the password
《原动力 x 云原生正发声 降本增效大讲堂》第三讲——Kubernetes 集群利用率提升实践
EasyCVR无法使用WebRTC进行播放,该如何解决?
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
深耕开发者生态,加速AI产业创新发展 英特尔携众多合作伙伴共聚
Win11 control panel shortcut key win11 multiple methods to open the control panel
Digital chemical plant management system based on Virtual Simulation Technology
Meaning of 'n:m' and '1:n' in database design
Implementation of JSTL custom function library
抖音或将推出独立种草社区平台:会不会成为第二个小红书
组织实战攻防演练的5个阶段
mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
什么是Web3
Fix the problem that the highlight effect of the main menu disappears when the easycvr Video Square is clicked and played
关于01背包个人的一些理解
Introduction to the PureMVC series
[multi threading exercise] write a multi threading example of the producer consumer model.
ESG全球领导者峰会|英特尔王锐:以科技之力应对全球气候挑战