WEBVTT

00:00.890 --> 00:08.090
JavaScript is a different language from other programming languages like Java, C, Sharp or B, and

00:08.090 --> 00:13.730
the one thing that makes JavaScript even more different from them is prototypic inheritance.

00:14.240 --> 00:16.340
So what is Prototyp inheritance?

00:16.910 --> 00:17.990
Up until this point?

00:18.020 --> 00:20.350
Maybe you have not heard any of these words.

00:20.810 --> 00:25.860
It sounds complicated, but you don't have to worry because I'm going to explain it deeper.

00:26.420 --> 00:31.730
So in JavaScript, every object inherits properties and methods from its prototype.

00:32.300 --> 00:35.690
And actually this relationship is called inheritance.

00:36.560 --> 00:39.010
Prototype itself is an object.

00:39.950 --> 00:47.530
So in other words, objects are linked to other objects and those linked objects are called the prototype.

00:48.530 --> 00:51.800
The prototype is automatically assigned to any object.

00:53.080 --> 00:59.900
OK, as we said, JavaScript is different from other programming languages because of that prototypic

00:59.930 --> 01:00.590
inheritance.

01:01.460 --> 01:06.320
Those languages provide kind of different type of inheritance, which is called classical.

01:07.330 --> 01:14.470
Some of the developers think that prototype inheritance is one of the downsides of JavaScript, but

01:14.470 --> 01:19.240
some of them think opposite, in my opinion, to work with prototype.

01:19.300 --> 01:22.480
Inheritance is much more convenient and flexible.

01:23.650 --> 01:27.160
In case of JavaScript, the engine does automatically.

01:27.160 --> 01:28.320
Lots of work for you.

01:28.810 --> 01:35.890
But for example, in case of classical inheritance, you have to create classes and then organize the

01:35.890 --> 01:37.000
relationship between them.

01:38.230 --> 01:40.960
OK, I'm not going to describe it deeper.

01:41.350 --> 01:46.900
The fact is that you have to do less work in JavaScript when you deal with Prototyp inheritance.

01:48.430 --> 01:48.880
All right.

01:49.270 --> 01:50.740
Without practical examples.

01:50.770 --> 01:53.050
This still sounds complicated.

01:53.530 --> 01:56.440
So let's go back to Brackett's and write some code.

01:58.370 --> 02:03.980
You already know how to create objects, you can use either literal notation.

02:05.160 --> 02:05.580
Or.

02:06.890 --> 02:11.270
Construct a rotation using new operator.

02:12.970 --> 02:19.300
So here we have two empty objects, let's lock them in Castle, White Castle, not like a.

02:22.420 --> 02:24.070
And then consider Lockerby.

02:27.870 --> 02:28.440
Revote.

02:30.030 --> 02:34.800
And I see that we have two empty objects, let's drop down them.

02:36.910 --> 02:44.590
So we have something else you see underscore, underscore Proteau on the score, which is a special

02:44.590 --> 02:51.250
property and points or is linked to object, let's drop down them as well.

02:53.080 --> 02:57.790
You see here a couple of built in methods, and for both objects, they are similar.

02:58.900 --> 03:04.750
So let me explain what's going on here so that we need to know actually what happens behind the scenes

03:05.770 --> 03:13.570
when we create objects using a literal or constructed notations each time we call builtin global object

03:13.570 --> 03:13.990
function.

03:14.990 --> 03:24.770
So if we write in council object, then we will get the motion global object function, I say object

03:24.770 --> 03:26.780
function because its name is object.

03:28.840 --> 03:35.380
This function allows us to create objects, it assigns property to them, which is underscore, underscore,

03:35.420 --> 03:40.720
Proteau, underscore, underscore, and using this property, objects have access on those methods.

03:42.040 --> 03:44.650
So where do all of these methods come from?

03:45.400 --> 03:51.790
In order to find out, we can use prototype property with this global object function and get access

03:51.790 --> 03:52.930
on the machine methods.

03:53.680 --> 03:54.160
That's right.

03:54.170 --> 03:56.050
Object dot prototype.

03:59.190 --> 04:07.200
Let's drop down and you see that we have here exact similar methods as it was in case of Proteau.

04:08.400 --> 04:14.490
So this object and this one are the same in order to prove that.

04:14.640 --> 04:15.260
That's right.

04:15.720 --> 04:18.090
Object dot prototype.

04:19.200 --> 04:20.130
Dot caret.

04:22.520 --> 04:23.720
Equals low.

04:26.780 --> 04:36.950
Reload, as you see here, we have new property, grit, and if we right your object prototype.

04:40.410 --> 04:45.590
Then because of that, those are the same objects we'll get inside it, Garet, as well.

04:47.200 --> 04:53.800
All right, again, when we create objects using literal or constructed notation, automatically we

04:53.800 --> 05:00.760
call global object function, which actually creates those objects and allows them to have link to its

05:00.760 --> 05:01.760
prototype object.

05:03.070 --> 05:03.700
Makes sense.

05:05.220 --> 05:09.790
OK, I know that it's confusing and difficult to understand.

05:09.810 --> 05:17.820
So let me explain once again here we have a built in global object function which has its prototype

05:17.820 --> 05:24.510
object, and it also has access on its prototype object using prototype property.

05:26.000 --> 05:33.440
When we have created objects variable A using literal notation and variable B using constructor notation.

05:34.670 --> 05:40.250
You know that these methods do the same job, but Litoral is more convenient and short on way.

05:41.750 --> 05:48.710
Then both of them invoke object function, which is also a function constructor, and after that it

05:48.710 --> 05:56.410
creates empty objects and assigns to them this underscore, underscore, Proteau underscore, underscore

05:56.410 --> 06:02.130
a property which then allows them to access on the prototype object.

06:03.080 --> 06:09.860
So you see that these newly created objects are the prototype object, which is prototype of global

06:09.860 --> 06:10.820
object function.

06:12.050 --> 06:12.560
All right.

06:13.220 --> 06:14.480
I think it makes sense.

06:14.750 --> 06:19.190
All of those stuff happens behind the scenes when we deal with global object.

06:19.190 --> 06:21.560
Constructor function is the next video.

06:21.560 --> 06:26.680
We'll continue talking about prototypes with manually created function constructors.

06:28.010 --> 06:29.180
See you in the next lecture.
