JavaScript is a different language from other programming languages like Java, C, Sharp or B, and
the one thing that makes JavaScript even more different from them is prototypic inheritance.
So what is Prototyp inheritance?
Up until this point?
Maybe you have not heard any of these words.
It sounds complicated, but you don't have to worry because I'm going to explain it deeper.
So in JavaScript, every object inherits properties and methods from its prototype.
And actually this relationship is called inheritance.
Prototype itself is an object.
So in other words, objects are linked to other objects and those linked objects are called the prototype.
The prototype is automatically assigned to any object.
OK, as we said, JavaScript is different from other programming languages because of that prototypic
inheritance.
Those languages provide kind of different type of inheritance, which is called classical.
Some of the developers think that prototype inheritance is one of the downsides of JavaScript, but
some of them think opposite, in my opinion, to work with prototype.
Inheritance is much more convenient and flexible.
In case of JavaScript, the engine does automatically.
Lots of work for you.
But for example, in case of classical inheritance, you have to create classes and then organize the
relationship between them.
OK, I'm not going to describe it deeper.
The fact is that you have to do less work in JavaScript when you deal with Prototyp inheritance.
All right.
Without practical examples.
This still sounds complicated.
So let's go back to Brackett's and write some code.
You already know how to create objects, you can use either literal notation.
Or.
Construct a rotation using new operator.
So here we have two empty objects, let's lock them in Castle, White Castle, not like a.
And then consider Lockerby.
Revote.
And I see that we have two empty objects, let's drop down them.
So we have something else you see underscore, underscore Proteau on the score, which is a special
property and points or is linked to object, let's drop down them as well.
You see here a couple of built in methods, and for both objects, they are similar.
So let me explain what's going on here so that we need to know actually what happens behind the scenes
when we create objects using a literal or constructed notations each time we call builtin global object
function.
So if we write in council object, then we will get the motion global object function, I say object
function because its name is object.
This function allows us to create objects, it assigns property to them, which is underscore, underscore,
Proteau, underscore, underscore, and using this property, objects have access on those methods.
So where do all of these methods come from?
In order to find out, we can use prototype property with this global object function and get access
on the machine methods.
That's right.
Object dot prototype.
Let's drop down and you see that we have here exact similar methods as it was in case of Proteau.
So this object and this one are the same in order to prove that.
That's right.
Object dot prototype.
Dot caret.
Equals low.
Reload, as you see here, we have new property, grit, and if we right your object prototype.
Then because of that, those are the same objects we'll get inside it, Garet, as well.
All right, again, when we create objects using literal or constructed notation, automatically we
call global object function, which actually creates those objects and allows them to have link to its
prototype object.
Makes sense.
OK, I know that it's confusing and difficult to understand.
So let me explain once again here we have a built in global object function which has its prototype
object, and it also has access on its prototype object using prototype property.
When we have created objects variable A using literal notation and variable B using constructor notation.
You know that these methods do the same job, but Litoral is more convenient and short on way.
Then both of them invoke object function, which is also a function constructor, and after that it
creates empty objects and assigns to them this underscore, underscore, Proteau underscore, underscore
a property which then allows them to access on the prototype object.
So you see that these newly created objects are the prototype object, which is prototype of global
object function.
All right.
I think it makes sense.
All of those stuff happens behind the scenes when we deal with global object.
Constructor function is the next video.
We'll continue talking about prototypes with manually created function constructors.
See you in the next lecture.