Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 12024bc

Browse files
committed
minor fixes
1 parent 1dc862c commit 12024bc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎1-js/04-object-basics/02-object-copy/article.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ let user = {
203203
alert( user.sizes.height ); // 182
204204
```
205205
206-
Now it's not enough to copy `clone.sizes = user.sizes`. `user.sizes` is an object, and will be copied by reference, so `clone` and `user` will share the same sizes:
206+
Now it's not enough to copy `clone.sizes = user.sizes`, because `user.sizes` is an object, and will be copied by reference, so `clone` and `user` will share the same sizes:
207207
208208
```js run
209209
let user = {
@@ -220,10 +220,10 @@ alert( user.sizes === clone.sizes ); // true, same object
220220

221221
// user and clone share sizes
222222
user.sizes.width++; // change a property from one place
223-
alert(clone.sizes.width); // 51, see the result from the other one
223+
alert(clone.sizes.width); // 51, get the result from the other one
224224
```
225225
226-
To fix that, we should use a cloning loop that examines each value of `user[key]` and, if it's an object, then replicate its structure as well. That is called a "deep cloning".
226+
To fix that and make `user` and `clone` truly separate objects, we should use a cloning loop that examines each value of `user[key]` and, if it's an object, then replicate its structure as well. That is called a "deep cloning".
227227
228228
We can use recursion to implement it. Or, to not reinvent the wheel, take an existing implementation, for instance [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep) from the JavaScript library [lodash](https://lodash.com).
229229

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /