WEBVTT

00:01.190 --> 00:05.840
So we have come to the point where you will introduce to one of the biggest additions in year six,

00:05.840 --> 00:11.480
which is closest, if you are familiar with other object oriented programming languages, then classes

00:11.480 --> 00:12.440
won't be new for you.

00:12.920 --> 00:17.030
But in ethics, classes are not like classes in other object oriented programming.

00:17.030 --> 00:23.390
Languages like Java, C, Sharp, PHP and many others in JavaScript classes are just syntactic sugar

00:23.390 --> 00:25.310
and they make our job much easier.

00:26.150 --> 00:31.790
Actually, classes like Function Constructors, which we have already learned in this lecture, I'm

00:31.790 --> 00:39.650
going to compare it five to six and therefore let's recall how function constructors work, create function.

00:40.850 --> 00:41.480
Person.

00:41.630 --> 00:42.560
Yes, five.

00:44.200 --> 00:50.590
With some parameters, right, first name, that last name.

00:52.400 --> 00:53.200
And H.

00:55.580 --> 00:59.630
As you remember, we need to right then restart first name.

01:01.430 --> 01:03.470
Equals to first name.

01:05.640 --> 01:13.670
Then they stopped last name, it was the last name and do the same for age, right?

01:13.710 --> 01:16.200
Is that H equals to H.

01:18.630 --> 01:24.600
Now, using this construction function, I'm going to create a brand new object using new operator,

01:24.780 --> 01:27.630
right, constant Niek yes, five.

01:29.570 --> 01:40.010
Equals the new person is five and then in search of your arguments as a first name, right, Nick Dan

01:40.880 --> 01:44.630
Smith and as The Age, right, 28.

01:45.930 --> 01:49.280
OK, let's consider what this object looks like right now.

01:49.430 --> 01:50.270
It's five.

01:52.280 --> 01:59.840
So here we have person object with properties and with relevant values, also we have here underscore,

01:59.840 --> 02:05.540
underscore, Proteau, underscore, underscore, which as you remember, is assigned by a function constructor

02:05.540 --> 02:07.760
in order to get access and prototype object.

02:08.720 --> 02:13.820
And also you see here another underscore, underscore, Proteau, underscore, underscore, which actually

02:13.820 --> 02:17.210
allows us to get access on global object function prototype.

02:18.270 --> 02:23.940
Because of that, we have access on prototype object of function constructor, we can assign to it the

02:23.940 --> 02:27.490
method which can be used for every brand new object.

02:28.530 --> 02:31.140
So that's the right person.

02:31.140 --> 02:35.040
S5 five DOT prototype dot.

02:35.610 --> 02:41.700
And right here, the method name about person then assigned to it, anonymous function.

02:44.430 --> 02:45.960
And running council.

02:47.700 --> 02:48.960
The following text.

02:51.140 --> 02:55.190
My name is then insert here.

02:56.310 --> 02:57.570
These dot first name.

03:00.030 --> 03:01.920
Then there's the last name.

03:03.830 --> 03:07.550
And I am an insert here, these dot age.

03:10.130 --> 03:11.150
Years old.

03:12.280 --> 03:16.600
All right, let's call this method for person Niek, it's five.

03:20.870 --> 03:26.480
Reload and we have my name is Nick Smith and I am 28 years old.

03:27.650 --> 03:28.100
All right.

03:28.220 --> 03:32.180
That's the way how we deal with function constructors and prototypes in years five.

03:32.840 --> 03:34.730
Now, let's see what happens in six.

03:35.750 --> 03:39.310
So to read the same stuff, we need to use class keyword.

03:39.830 --> 03:42.170
But before that, let's make here a powder.

03:45.990 --> 03:53.010
And then right klus, which is followed by the name of the class that's right here, person Yes, six.

03:54.750 --> 03:59.130
So actually using different syntax, we have created a function constructor.

03:59.550 --> 04:04.360
And to prove that, let's check the type of class right consultor blog.

04:05.390 --> 04:09.930
You see your type of operator and that person is six.

04:13.280 --> 04:17.210
Reload, and he said that it's a function.

04:17.990 --> 04:24.560
All right, the next thing that we have to do is to use constructor methods in order to assign properties

04:24.560 --> 04:25.870
to the brand new object.

04:26.150 --> 04:26.410
So.

04:26.420 --> 04:26.780
Right.

04:27.260 --> 04:28.580
Keyword constructor.

04:31.510 --> 04:37.240
And here we need to place the parameters, so let's copy them and.

04:39.150 --> 04:39.930
Paste here.

04:45.740 --> 04:51.870
And now it's time to create a brand new object, so write consent, Nick.

04:52.020 --> 04:52.940
Yes, six.

04:55.610 --> 04:56.720
Equals two new.

04:57.780 --> 04:59.010
Person is six.

05:01.800 --> 05:05.610
And then place your arguments right, Nick, as first name.

05:07.180 --> 05:11.980
Then again, Smith and as the age right 28.

05:13.910 --> 05:16.620
Let's check in cons. this object, right, Nic?

05:16.670 --> 05:17.570
Yes, six.

05:20.640 --> 05:28.050
So here we have person ESX object with properties and values, so this person looks like in the exact

05:28.050 --> 05:31.140
same way as it was in case of person is five.

05:32.070 --> 05:32.670
That's right.

05:33.160 --> 05:34.020
Yes, five.

05:35.910 --> 05:39.690
If we drop down, it's you will find that those two objects are almost similar.

05:40.170 --> 05:46.550
The only distinction is that in prototype object of personal use five, we have a method about person.

05:48.000 --> 05:54.210
So to achieve the same in ethics classes is much more easier because we can do it without writing any

05:54.210 --> 05:54.950
prototypes.

05:55.740 --> 05:57.240
So let's see how we can do that.

05:57.460 --> 06:02.460
The first thing to note is that after a constructor method, we don't need to place your Colma.

06:02.820 --> 06:04.590
We can directly create method.

06:05.430 --> 06:06.810
Let's call it about person.

06:08.780 --> 06:10.990
Then grew up from person.

06:11.180 --> 06:14.570
Five, this content and.

06:16.630 --> 06:17.380
Paste here.

06:20.470 --> 06:26.770
Let's call this method for ethics, right, ethics, thought about personal.

06:29.760 --> 06:32.510
Reload and we have the same results.

06:33.550 --> 06:38.740
So actually, we have achieved the exact same, but as you see, in much more easier and convenient

06:38.740 --> 06:38.980
way.

06:39.730 --> 06:43.650
All right, let's move on and talk about prototypic inheritance.

06:44.320 --> 06:46.780
I'm going to create another function constructor.

06:47.910 --> 06:49.870
Let's call it developer.

06:49.920 --> 06:50.730
Yes, five.

06:54.040 --> 07:04.630
And insert here parameters like first name, last name, then, right H.

07:05.920 --> 07:06.820
Experience.

07:09.590 --> 07:12.290
And the last one right here, projects.

07:14.730 --> 07:21.600
As you see, both function constructor's, have first name, last name and age parameters for those

07:21.600 --> 07:22.530
three parameters.

07:22.560 --> 07:25.520
I'm going to use personally as five constructor function.

07:26.220 --> 07:28.830
So we need to write personally as five.

07:30.340 --> 07:37.260
In order to receive developer s five constructor function properties of person is five constructor,

07:37.810 --> 07:41.940
we need to call personalness five and use the special variable.

07:42.030 --> 07:42.430
This.

07:44.720 --> 07:51.200
And also insert your first name, last name and age.

07:53.800 --> 08:02.350
So here, this variable points to brand new object, which will be created using developer, yes, five

08:02.350 --> 08:06.090
constructor function, that's for experience and project parameters.

08:06.100 --> 08:19.040
Let's write this thought experience equals to experience and that these DOT projects equals two projects.

08:19.870 --> 08:20.410
All right.

08:21.010 --> 08:31.140
Now let's create a new object right concept and call it Alex WDEF, then write a new developer.

08:31.570 --> 08:32.320
Yes, five.

08:32.560 --> 08:43.630
And as arguments that place you as the first name Alex, then Brown as last name, then the right authority

08:43.780 --> 08:50.790
as age 10 as experience and write the last one five as projects.

08:52.840 --> 08:54.250
OK, let's say in Castle.

08:55.420 --> 08:56.530
Right, Alex Dev.

08:58.610 --> 09:02.870
So you see that this object contains all the properties and values, as we expected.

09:03.710 --> 09:09.430
OK, let's say that we want to use about person method for newly created developer objects.

09:10.670 --> 09:12.290
For that, we have to do the following.

09:12.290 --> 09:20.060
We have to assign to prototype object of developer S5 construct to the copy of person as five prototype

09:20.060 --> 09:20.510
objects.

09:21.050 --> 09:23.940
And for that we need to use object and create method.

09:24.530 --> 09:26.750
So right developer iOS five.

09:27.590 --> 09:32.360
That prototype equals to objects that create.

09:35.330 --> 09:41.720
And inside parentheses, insert person is five dot prototype.

09:42.800 --> 09:50.240
So again, object to create method is used here because we need to create copy of person s five prototype

09:50.240 --> 09:50.690
object.

09:51.290 --> 09:54.890
And not only the reference to it makes sense.

09:55.820 --> 10:03.020
OK, so now we are able to use about person method from person use five prototype object and use it

10:03.020 --> 10:04.300
for developer object.

10:04.790 --> 10:06.530
So that's right Alex.

10:06.530 --> 10:12.170
That not about person reload.

10:13.260 --> 10:17.090
And we have my name is Alex Brown and I am 30 years old.

10:17.930 --> 10:23.780
So as you see Alex, that object has inherited matter from person is five prototype object.

10:25.080 --> 10:25.570
All right.

10:26.330 --> 10:31.700
Now I'm going to assign a new method to developer is five prototype object, which actually will be

10:31.700 --> 10:36.370
used only for brand new objects created by developer S5 constructor.

10:37.310 --> 10:38.300
So that's right.

10:38.570 --> 10:44.090
Developer S5 dot prototype that about that.

10:45.940 --> 10:48.190
And assigned to it function.

10:51.150 --> 10:56.330
Then write that log and that's yours.

10:56.380 --> 11:02.190
Here are the properties which we have assigned to developer s S5 constructor, so write the following.

11:02.730 --> 11:06.720
My name is then they start first name.

11:09.080 --> 11:17.990
Then use your last name, so right, this dot last name, then I am at this thought age.

11:22.100 --> 11:23.510
Years old, with

11:26.540 --> 11:28.130
and use your experience.

11:31.850 --> 11:44.670
Then, right, the tax, again, years of experience and I have participated in and right here, these

11:44.690 --> 11:45.500
DOT projects.

11:48.460 --> 11:49.510
And then projects.

11:51.910 --> 11:54.090
OK, let's call this method right?

11:57.210 --> 12:03.500
I look, staff thought about that, so if we reload, we will get.

12:04.570 --> 12:12.070
My name is Alex Brown, 30 years old, with 10 years of experience and I have participated in five projects.

12:12.610 --> 12:13.050
All right.

12:13.060 --> 12:17.470
So as we said, this method works only for objects which are created using developer.

12:17.740 --> 12:19.050
Yes, five constructor.

12:19.510 --> 12:24.280
And in order to prove that, let's call this method for Nexus five object as well.

12:24.730 --> 12:25.120
Right.

12:25.120 --> 12:29.260
Nikias five dots about def.

12:32.430 --> 12:40.530
Reload and see that we have an error, which tells us that about that is not a function in order to

12:40.530 --> 12:47.450
understand better why we have used objects that create method, let's get rid of it and leave only person

12:47.450 --> 12:49.050
who is five, that prototype object.

12:50.220 --> 12:57.750
Let's reload and you see that it works now for both objects, the only thing is that we have here undefined

12:57.750 --> 13:01.350
for experience and projects because actually person is five.

13:01.350 --> 13:03.570
Constructor doesn't have those parameters.

13:04.080 --> 13:04.610
All right.

13:05.250 --> 13:09.150
So, again, in this case, both constructors have the same prototype object.

13:09.750 --> 13:17.760
But when we use objects that create new copy of prototype object is created generally in S5, we always

13:17.760 --> 13:21.420
use objects to create a method for more privacy.

13:22.760 --> 13:28.550
OK, I believe you agree that in year five, there are lots of stuff to do regarding Prototyp inheritance,

13:29.150 --> 13:30.320
it's hard to understand.

13:30.320 --> 13:34.400
Also, it causes confusion if you are not an experienced JavaScript developer.

13:34.790 --> 13:38.670
But in case of Essex version, everything becomes much more simpler.

13:39.110 --> 13:44.690
Let's create another class for developer called developer execs.

13:45.920 --> 13:52.070
So in order to inherit from a person who has six properties and methods, we need to use keyword extents.

13:54.250 --> 13:56.290
And that person is six.

13:59.610 --> 14:05.820
Now, again, we have to use constructor method with all the parameters, so right here, constructor

14:07.080 --> 14:11.190
and then copy the parameters.

14:15.190 --> 14:23.110
Let's take a look on S5 version, so here we have used called Method, and I believe you have understood

14:23.110 --> 14:24.010
why we have done it.

14:24.820 --> 14:31.090
But in Essex, it's no longer needed because there exists a built in method called Super, which actually

14:31.090 --> 14:33.310
will call for an ethics class.

14:33.820 --> 14:40.810
So in this case, remember, that person is 6th class is called as super class and developer.

14:40.820 --> 14:43.540
Ethics class is called as subclass.

14:44.560 --> 14:57.340
All right, let's use super method and insert as arguments, first name, last name and age.

14:58.360 --> 15:05.320
And then for the rest of the parameters, I mean, experience and projects, we have to write this thought

15:05.320 --> 15:06.250
experience.

15:07.480 --> 15:11.980
Equals the experience and then they start projects.

15:14.300 --> 15:21.160
Equals two projects, besides that, we have about about 12 methods, so that's created

15:23.570 --> 15:27.080
and then copy the content

15:31.010 --> 15:31.970
and paste here.

15:33.230 --> 15:35.340
All right, everything is ready.

15:35.990 --> 15:37.580
I'm going to create a new object.

15:37.970 --> 15:48.920
Let's call it Bob Deve, which equals the new developer ethics and insert here arguments.

15:48.920 --> 15:52.130
Bob, as first name that James.

15:53.810 --> 16:05.940
That 40, 15 and for example, seven and then call about their method, right, Bob Taft thought about

16:05.940 --> 16:06.290
death.

16:10.060 --> 16:19.120
Reload and we have my name is Bob James, 40 years old, with 15 years of experience and I have participated

16:19.120 --> 16:20.590
in seven projects.

16:21.250 --> 16:25.600
All right, let's try to use about person method for bulked up object.

16:26.770 --> 16:27.090
Right.

16:27.100 --> 16:28.630
Bob Taft, what about person?

16:32.010 --> 16:35.590
Reload and see that it works perfectly as well.

16:36.300 --> 16:40.980
But if we try to use about that method for Nick, it's six object,

16:47.500 --> 16:48.930
then we will get an error.

16:49.620 --> 16:57.030
And I'm sure you guessed why when we use six behind the scenes happens the same stuff that was in case

16:57.030 --> 16:58.290
of using object.

16:58.300 --> 17:01.150
That great method makes sense.

17:01.470 --> 17:07.380
OK, I know that it was a bit hard lecture, but I try to show you clearly the difference between five

17:07.380 --> 17:14.010
and six when we deal with the type of inheritance, I hope you undecidable everything, but if not,

17:14.010 --> 17:16.110
you can watch the video carefully.

17:17.160 --> 17:18.810
All right, let's go ahead.
