So we have come to the point where you will introduce to one of the biggest additions in year six,
which is closest, if you are familiar with other object oriented programming languages, then classes
won't be new for you.
But in ethics, classes are not like classes in other object oriented programming.
Languages like Java, C, Sharp, PHP and many others in JavaScript classes are just syntactic sugar
and they make our job much easier.
Actually, classes like Function Constructors, which we have already learned in this lecture, I'm
going to compare it five to six and therefore let's recall how function constructors work, create function.
Person.
Yes, five.
With some parameters, right, first name, that last name.
And H.
As you remember, we need to right then restart first name.
Equals to first name.
Then they stopped last name, it was the last name and do the same for age, right?
Is that H equals to H.
Now, using this construction function, I'm going to create a brand new object using new operator,
right, constant Niek yes, five.
Equals the new person is five and then in search of your arguments as a first name, right, Nick Dan
Smith and as The Age, right, 28.
OK, let's consider what this object looks like right now.
It's five.
So here we have person object with properties and with relevant values, also we have here underscore,
underscore, Proteau, underscore, underscore, which as you remember, is assigned by a function constructor
in order to get access and prototype object.
And also you see here another underscore, underscore, Proteau, underscore, underscore, which actually
allows us to get access on global object function prototype.
Because of that, we have access on prototype object of function constructor, we can assign to it the
method which can be used for every brand new object.
So that's the right person.
S5 five DOT prototype dot.
And right here, the method name about person then assigned to it, anonymous function.
And running council.
The following text.
My name is then insert here.
These dot first name.
Then there's the last name.
And I am an insert here, these dot age.
Years old.
All right, let's call this method for person Niek, it's five.
Reload and we have my name is Nick Smith and I am 28 years old.
All right.
That's the way how we deal with function constructors and prototypes in years five.
Now, let's see what happens in six.
So to read the same stuff, we need to use class keyword.
But before that, let's make here a powder.
And then right klus, which is followed by the name of the class that's right here, person Yes, six.
So actually using different syntax, we have created a function constructor.
And to prove that, let's check the type of class right consultor blog.
You see your type of operator and that person is six.
Reload, and he said that it's a function.
All right, the next thing that we have to do is to use constructor methods in order to assign properties
to the brand new object.
So.
Right.
Keyword constructor.
And here we need to place the parameters, so let's copy them and.
Paste here.
And now it's time to create a brand new object, so write consent, Nick.
Yes, six.
Equals two new.
Person is six.
And then place your arguments right, Nick, as first name.
Then again, Smith and as the age right 28.
Let's check in cons. this object, right, Nic?
Yes, six.
So here we have person ESX object with properties and values, so this person looks like in the exact
same way as it was in case of person is five.
That's right.
Yes, five.
If we drop down, it's you will find that those two objects are almost similar.
The only distinction is that in prototype object of personal use five, we have a method about person.
So to achieve the same in ethics classes is much more easier because we can do it without writing any
prototypes.
So let's see how we can do that.
The first thing to note is that after a constructor method, we don't need to place your Colma.
We can directly create method.
Let's call it about person.
Then grew up from person.
Five, this content and.
Paste here.
Let's call this method for ethics, right, ethics, thought about personal.
Reload and we have the same results.
So actually, we have achieved the exact same, but as you see, in much more easier and convenient
way.
All right, let's move on and talk about prototypic inheritance.
I'm going to create another function constructor.
Let's call it developer.
Yes, five.
And insert here parameters like first name, last name, then, right H.
Experience.
And the last one right here, projects.
As you see, both function constructor's, have first name, last name and age parameters for those
three parameters.
I'm going to use personally as five constructor function.
So we need to write personally as five.
In order to receive developer s five constructor function properties of person is five constructor,
we need to call personalness five and use the special variable.
This.
And also insert your first name, last name and age.
So here, this variable points to brand new object, which will be created using developer, yes, five
constructor function, that's for experience and project parameters.
Let's write this thought experience equals to experience and that these DOT projects equals two projects.
All right.
Now let's create a new object right concept and call it Alex WDEF, then write a new developer.
Yes, five.
And as arguments that place you as the first name Alex, then Brown as last name, then the right authority
as age 10 as experience and write the last one five as projects.
OK, let's say in Castle.
Right, Alex Dev.
So you see that this object contains all the properties and values, as we expected.
OK, let's say that we want to use about person method for newly created developer objects.
For that, we have to do the following.
We have to assign to prototype object of developer S5 construct to the copy of person as five prototype
objects.
And for that we need to use object and create method.
So right developer iOS five.
That prototype equals to objects that create.
And inside parentheses, insert person is five dot prototype.
So again, object to create method is used here because we need to create copy of person s five prototype
object.
And not only the reference to it makes sense.
OK, so now we are able to use about person method from person use five prototype object and use it
for developer object.
So that's right Alex.
That not about person reload.
And we have my name is Alex Brown and I am 30 years old.
So as you see Alex, that object has inherited matter from person is five prototype object.
All right.
Now I'm going to assign a new method to developer is five prototype object, which actually will be
used only for brand new objects created by developer S5 constructor.
So that's right.
Developer S5 dot prototype that about that.
And assigned to it function.
Then write that log and that's yours.
Here are the properties which we have assigned to developer s S5 constructor, so write the following.
My name is then they start first name.
Then use your last name, so right, this dot last name, then I am at this thought age.
Years old, with
and use your experience.
Then, right, the tax, again, years of experience and I have participated in and right here, these
DOT projects.
And then projects.
OK, let's call this method right?
I look, staff thought about that, so if we reload, we will get.
My name is Alex Brown, 30 years old, with 10 years of experience and I have participated in five projects.
All right.
So as we said, this method works only for objects which are created using developer.
Yes, five constructor.
And in order to prove that, let's call this method for Nexus five object as well.
Right.
Nikias five dots about def.
Reload and see that we have an error, which tells us that about that is not a function in order to
understand better why we have used objects that create method, let's get rid of it and leave only person
who is five, that prototype object.
Let's reload and you see that it works now for both objects, the only thing is that we have here undefined
for experience and projects because actually person is five.
Constructor doesn't have those parameters.
All right.
So, again, in this case, both constructors have the same prototype object.
But when we use objects that create new copy of prototype object is created generally in S5, we always
use objects to create a method for more privacy.
OK, I believe you agree that in year five, there are lots of stuff to do regarding Prototyp inheritance,
it's hard to understand.
Also, it causes confusion if you are not an experienced JavaScript developer.
But in case of Essex version, everything becomes much more simpler.
Let's create another class for developer called developer execs.
So in order to inherit from a person who has six properties and methods, we need to use keyword extents.
And that person is six.
Now, again, we have to use constructor method with all the parameters, so right here, constructor
and then copy the parameters.
Let's take a look on S5 version, so here we have used called Method, and I believe you have understood
why we have done it.
But in Essex, it's no longer needed because there exists a built in method called Super, which actually
will call for an ethics class.
So in this case, remember, that person is 6th class is called as super class and developer.
Ethics class is called as subclass.
All right, let's use super method and insert as arguments, first name, last name and age.
And then for the rest of the parameters, I mean, experience and projects, we have to write this thought
experience.
Equals the experience and then they start projects.
Equals two projects, besides that, we have about about 12 methods, so that's created
and then copy the content
and paste here.
All right, everything is ready.
I'm going to create a new object.
Let's call it Bob Deve, which equals the new developer ethics and insert here arguments.
Bob, as first name that James.
That 40, 15 and for example, seven and then call about their method, right, Bob Taft thought about
death.
Reload and we have my name is Bob James, 40 years old, with 15 years of experience and I have participated
in seven projects.
All right, let's try to use about person method for bulked up object.
Right.
Bob Taft, what about person?
Reload and see that it works perfectly as well.
But if we try to use about that method for Nick, it's six object,
then we will get an error.
And I'm sure you guessed why when we use six behind the scenes happens the same stuff that was in case
of using object.
That great method makes sense.
OK, I know that it was a bit hard lecture, but I try to show you clearly the difference between five
and six when we deal with the type of inheritance, I hope you undecidable everything, but if not,
you can watch the video carefully.
All right, let's go ahead.