1
00:00:01,192 --> 00:00:02,840
Another useful feature of the spread

2
00:00:02,840 --> 00:00:06,154
operator is used to perform a shallow copy

3
00:00:06,154 --> 00:00:08,797
on object literals. Let's take a look at

4
00:00:08,797 --> 00:00:13,247
how this works. In this function

5
00:00:13,247 --> 00:00:15,273
objectLiterals, I've created a literal

6
00:00:15,273 --> 00:00:19,598
object called product, and I assign it a

7
00:00:19,598 --> 00:00:22,769
few different properties. Down here on

8
00:00:22,769 --> 00:00:26,446
line 26 I let prod2 equal to, in curly

9
00:00:26,446 --> 00:00:29,414
braces, right, that's an object literal,

10
00:00:29,414 --> 00:00:32,641
…product. So again, what it's going to do

11
00:00:32,641 --> 00:00:34,639
is take each of these objects and perform

12
00:00:34,639 --> 00:00:36,933
a shallow copy. Now this is very similar

13
00:00:36,933 --> 00:00:41,495
to the JavaScript object.assign method. We

14
00:00:41,495 --> 00:00:43,671
then can change one of the newly copied

15
00:00:43,671 --> 00:00:46,690
objects, and we could actually change one

16
00:00:46,690 --> 00:00:49,497
of those properties and see if it now is a

17
00:00:49,497 --> 00:00:52,497
by-reference or by-value type of thing.

18
00:00:52,497 --> 00:00:54,032
But since we're doing a shallow copy, I

19
00:00:54,032 --> 00:00:56,560
think you already know the answer. On

20
00:00:56,560 --> 00:00:59,042
lines 32 and 33 I'll print out each of the

21
00:00:59,042 --> 00:01:00,809
objects, and then we'll display the

22
00:01:00,809 --> 00:01:04,584
changed value of the productID from both

23
00:01:04,584 --> 00:01:11,600
objects on lines 37 and 38. So here we

24
00:01:11,600 --> 00:01:14,689
have our two objects. The one did indeed

25
00:01:14,689 --> 00:01:16,790
get copied. Only the second one, the

26
00:01:16,790 --> 00:01:19,483
copied one, did get changed. So it does

27
00:01:19,483 --> 00:01:26,000
actually a copy property by property from one object to the other.

