1 00:00:01,070 --> 00:00:05,410 So objects like a raise have a separate operator that allow you to break an object apart. 2 00:00:05,930 --> 00:00:07,730 So here's a couple of things you can do. 3 00:00:09,870 --> 00:00:17,040 You can say let an object equals and then in curly braces, use the spread operator, dot, dot, dot 4 00:00:17,460 --> 00:00:20,880 myod, which is another object and it makes it clone. 5 00:00:21,670 --> 00:00:28,260 And just like with a raise, if you say let OB's equals myod, it's just going to be another pointer 6 00:00:28,260 --> 00:00:29,270 to the same object. 7 00:00:30,360 --> 00:00:35,000 So if you do a clone, it makes a copy of it, but only does a shallow copy. 8 00:00:35,460 --> 00:00:39,750 So if you have objects within objects with an object, it's only going to copy the upper level 9 00:00:42,720 --> 00:00:44,320 and then you can merge two objects. 10 00:00:44,700 --> 00:00:51,690 You can say that an object equals dot, dot, dot, obj, one dot, dot, dot, object two. 11 00:00:52,470 --> 00:00:54,650 So it makes one object out of two objects. 12 00:00:55,440 --> 00:00:57,170 So let's look at a couple examples. 13 00:00:59,580 --> 00:01:00,000 All right. 14 00:01:00,010 --> 00:01:05,310 So let's create an object and we'll just say let 15 00:01:07,770 --> 00:01:18,120 object equals and we'll say name Bill, age thirty three. 16 00:01:18,120 --> 00:01:19,980 We don't have to supply a lot of information. 17 00:01:21,270 --> 00:01:34,000 So then just to demonstrate, if we say let my object equals OBJ and then say in my obj that age plus 18 00:01:34,050 --> 00:01:39,600 plus a year has gone by and we said cancel that log. 19 00:01:41,340 --> 00:01:48,330 The original object that we see is that it's going to be thirty four. 20 00:01:49,790 --> 00:01:50,960 Let's take a look. 21 00:01:53,220 --> 00:01:56,530 So now Bill is 34, so both objects are the same. 22 00:01:57,150 --> 00:02:05,550 So if we did it instead with the spread operator, if we said curly brace, dot, dot, dot, curly 23 00:02:05,550 --> 00:02:09,780 brace, and we'll output both OBJ and my abs. 24 00:02:13,590 --> 00:02:18,150 Now we see we have a bill whose age is 33 and a bill whose age is thirty four. 25 00:02:19,070 --> 00:02:22,610 Now, what about having a deep definition? 26 00:02:23,280 --> 00:02:31,680 So if we say have a set object profession, name 27 00:02:35,280 --> 00:02:36,000 carpenter 28 00:02:39,060 --> 00:02:39,990 and. 29 00:02:44,260 --> 00:02:46,760 Experience, two years. 30 00:02:47,860 --> 00:02:50,480 So now we have more of a deeper object. 31 00:02:50,950 --> 00:02:53,530 So now what happens if we do this? 32 00:03:00,890 --> 00:03:03,240 So we have the same thing. 33 00:03:04,190 --> 00:03:07,820 So if we go into my arms and change the experience. 34 00:03:13,410 --> 00:03:18,330 Firsthand experience plus plus. 35 00:03:22,460 --> 00:03:29,120 So see that this one's three and this one's also three, so it only made a shallow copy. 36 00:03:29,120 --> 00:03:35,820 So profession is as if we did what we did originally and said biologicals or object is my art. 37 00:03:36,560 --> 00:03:39,740 So this thing did not get cloned, so you'd have to clone each part. 38 00:03:40,760 --> 00:03:42,700 So now let's merge two objects. 39 00:03:43,520 --> 00:03:49,250 So instead of it being like this, let's make another object 40 00:03:51,890 --> 00:04:02,630 and say what profession equals and. 41 00:04:07,570 --> 00:04:16,930 So now we have two objects, so now if we said object that that profession, then my arms would be both 42 00:04:16,930 --> 00:04:17,360 of them. 43 00:04:18,490 --> 00:04:25,560 So we can't do this, but we could do my abs. 44 00:04:27,420 --> 00:04:29,950 That experience crosspost. 45 00:04:31,600 --> 00:04:32,830 So let's see what happens. 46 00:04:37,070 --> 00:04:47,660 The name here is the same in both, so we're going to get a collision, so let's change this to P name, 47 00:04:47,660 --> 00:04:48,500 profession, name. 48 00:04:53,830 --> 00:04:59,320 And so now we have named Bill, age 34 penname as carpenter and experiences three. 49 00:05:01,390 --> 00:05:04,330 So that's an introduction to the spread operator with objects.