当前位置:网站首页>[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
ExporterChange ,Import sideWill change .
边栏推荐
- DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
- The easycvr platform is connected to the RTMP protocol, and the interface call prompts how to solve the error of obtaining video recording?
- 每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报
- Acl2022 | decomposed meta learning small sample named entity recognition
- The request request is encapsulated in uni app, which is easy to understand
- 掌握软件安全测试方法秘笈,安全测试报告信手捏来
- Structure actual training camp | after class homework | module 6
- 软件测试之网站测试如何进行?测试小攻略走起!
- MySQL null value processing and value replacement
- NTU notes 6422quiz review (1-3 sections)
猜你喜欢

mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi

EasyCVR平台接入RTMP协议,接口调用提示获取录像错误该如何解决?

Programmers go to work fishing, so play high-end!

Basic idea of counting and sorting

What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures

NFT meta universe chain diversified ecosystem development case

NTU notes 6422quiz review (1-3 sections)

buildroot的根文件系统提示“depmod:applt not found”

In depth analysis of kubebuilder

视频融合云平台EasyCVR视频广场左侧栏列表样式优化
随机推荐
Network Security Learning - Information Collection
Acl2022 | decomposed meta learning small sample named entity recognition
微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
In depth analysis of kubebuilder
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
主设备号和次设备号均为0
[team learning] [phase 34] Baidu PaddlePaddle AI talent Creation Camp
acwing 843. n-皇后问题
Programmers go to work fishing, so play high-end!
论文上岸攻略 | 如何快速入门学术论文写作
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
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
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
What is JVM? What are the purposes of JVM tuning?
System framework of PureMVC
How to solve the problem of adding RTSP device to easycvr cluster version and prompting server ID error?
Jetson nano configures pytorch deep learning environment / / to be improved
namespace基础介绍