In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge of this "es6 deconstruction is a deep copy" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "es6 deconstruction is a deep copy" article.
Es6 deconstruction is not a deep copy. If the deconstructed original object is an one-dimensional array or object, then deconstruction is a deep copy, and if the deconstructed original object is a multi-dimensional array or object, then deconstruction is a shallow copy, because deconstruction cannot achieve the effect of deep copy of a multi-dimensional array, so deconstruction is not a deep copy, it should be a shallow copy.
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
Is es6 deconstruction a deep copy?
You must be familiar with the knowledge of deconstruction assignment in ES6. A deconstruction assignment is a scheme that uses a pattern to quickly fetch data from the target structure, such as:
By deconstructing, we can easily extract the data we want from arrays and objects. However, you may ask, what does this have to do with deep copy or shallow copy?
Let's first review about deep copy and shallow copy.
The so-called shallow copy and deep copy: in the copy process, the traversal part points to the original address for the object / array type, while the deep copy completely opens up a new memory address. That is to say,
Deep copy: modifying the value of a new variable does not affect the value of the original variable. By default, the basic data type (number,string,null,undefined,boolean) is a deep copy.
Shallow copy: changing the value of a new variable will affect the value of the original variable. By default, reference types (object) are shallow copies.
So, in deconstruction, is it a deep copy or a shallow copy?
In the above code, we deconstruct the array and object respectively, then modify the value of the deconstructed variable, and then print the variable and the original array and object respectively. The result is as follows:
We find that the data of the original array and object have not changed, does it mean that the deconstruction assignment is a deep copy?
Let's modify the example a little bit and the code is as follows:
We added a data attribute for the object, and the data of data is an array. After deconstructing, we modify the data of data. The result is as follows:
We find that the change of the deconstructed variable data causes the change of the original data, that is, the deconstruction assignment is still a shallow copy.
The above is about the content of this article on whether es6 deconstruction is a deep copy or not. I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.