Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,660 --> 00:00:04,540
In the last section, we spoke about constructor functions defined on classes.
2
00:00:05,040 --> 00:00:09,690
We also went through a little bit of a shortcut on assigning a property straight through the constructor
3
00:00:09,690 --> 00:00:13,920
without having to add any additional function code to the constructor itself.
4
00:00:14,520 --> 00:00:18,300
So in this section, we're going to do a quick review on what just happened, just to make sure that
5
00:00:18,300 --> 00:00:23,760
it's really crystal clear, because this abbreviated syntax right here of initializing a property name
6
00:00:23,760 --> 00:00:28,200
directly from the constructor is something that you're going to see all throughout this course in a
7
00:00:28,200 --> 00:00:31,010
tremendous amount of documentation on D'Arte as well.
8
00:00:31,350 --> 00:00:32,369
So let's get to it.
9
00:00:32,729 --> 00:00:36,060
And I put together a quick diagram to help you understand what is going on.
10
00:00:36,750 --> 00:00:41,700
And the first thing I want to remind you about is that you and I added a function to the class.
11
00:00:42,510 --> 00:00:49,590
The functions name was person with a capital P because that function name was absolutely, positively
12
00:00:49,590 --> 00:00:51,630
identical to the class name.
13
00:00:51,870 --> 00:00:55,920
It became the constructor function for this class automatically.
14
00:00:56,880 --> 00:01:01,980
Remember, a constructor function gets called automatically any time that's been defined on the class,
15
00:01:01,980 --> 00:01:06,840
and it is our place to do some initialization or setup of the class instance.
16
00:01:08,550 --> 00:01:15,270
Inside this constructor, we specified an argument list with exactly one argument on it, inside that
17
00:01:15,270 --> 00:01:17,950
argument list, we wrote out this first name.
18
00:01:18,630 --> 00:01:24,540
This means that in order for us to create a new instance of a person, we have to call a new person
19
00:01:24,780 --> 00:01:27,750
and provide exactly one argument to it.
20
00:01:27,960 --> 00:01:33,390
So specifically because we wrote out an argument right here that means any time we create a new instance
21
00:01:33,390 --> 00:01:36,510
of a person, we have to provide one argument as well.
22
00:01:38,160 --> 00:01:43,080
Now, the interesting thing about that argument that we listed there was that on the front of the argument
23
00:01:43,080 --> 00:01:50,700
name we put on this dot and then we wrote out a property name or the name of a property or field that
24
00:01:50,700 --> 00:01:57,690
belongs to this class because we followed that strict rules because we have this dot and then exactly
25
00:01:57,690 --> 00:02:03,540
the field name right here darte decided to automatically take this argument of string, Stephen, right
26
00:02:03,540 --> 00:02:08,970
here or whatever your name is in your case, and automatically assign it to the first name property
27
00:02:08,970 --> 00:02:09,600
for us.
28
00:02:10,020 --> 00:02:16,350
So again, specifically because we used this dot and then the exact name of the property, this got
29
00:02:16,350 --> 00:02:22,020
assigned to the correct property name for us to give you a very, very quick demonstration of exactly
30
00:02:22,020 --> 00:02:22,620
how that worked.
31
00:02:22,740 --> 00:02:24,600
I'll flip back over to Pat over here.
32
00:02:25,930 --> 00:02:31,210
Now I want to find that constructor function and I'm going to try changing first name right here to
33
00:02:31,210 --> 00:02:34,660
something else, like maybe something like my first name.
34
00:02:35,920 --> 00:02:40,930
Now, when I do so, you'll notice that I've got an error message down here, it says My first name
35
00:02:40,930 --> 00:02:43,070
isn't a field on the inclosing class.
36
00:02:43,750 --> 00:02:46,990
However, if I remove the this dot from this thing.
37
00:02:48,060 --> 00:02:53,070
Then you'll notice that the error message goes away, so it's specifically the combination there of
38
00:02:53,070 --> 00:03:00,870
putting this dot and the exact property name that allows us to take this shortcut in adding this property
39
00:03:01,170 --> 00:03:02,520
to the class person.
40
00:03:03,360 --> 00:03:09,480
So I'm now going to revert that back to this dot first name and now my code is going to work as it did
41
00:03:09,480 --> 00:03:11,250
before, exactly as we expect.
42
00:03:12,180 --> 00:03:17,100
OK, so again, in the section we spoke about constructor's and we spoke about this little shortcut
43
00:03:17,100 --> 00:03:23,400
right here for assigning fields to a instance of a class, whenever we call the constructor function
44
00:03:23,610 --> 00:03:28,490
and we call that constructor function by using the new keyword right here and then referencing the class
45
00:03:28,500 --> 00:03:28,800
name.
46
00:03:29,720 --> 00:03:34,210
It's now that we've got a good overview on this, let's continue in the next section where we're going
47
00:03:34,210 --> 00:03:38,430
to start working on our next project that's going to heavily involve classes.
48
00:03:38,740 --> 00:03:40,920
So quick break and I'll see you in just a minute.
5263
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.