Hello Guys,
My name is Joel Mukanya.
Am a CEO and FOunder at JT Devs
For today's video we going to focus on prototype and inheritance.
So I'm going to start with a basic example.
Then we can compare when we need to use a prototype.
So this will be kind of creating a class then we said Person
This dot name equals to Duke
Then we have this dot surname equals to Sam.
First we need to create an object.
Object one equals to new Person
Then we have person one. Now we need to display the value.
I can also create person two, so that we can see the difference then new Person.
Let display those values, so we have person one dot age equals to 30
And for person two dot age is equals to 31.
console.log name: dot concat, we have person one dot name
a new line surname: person one
dot surname.
person one dot age, then let do the
same thing for person two.
We just have to change it from person 1 to 2
Let have a look
We can save it, we just have to make sure that is it saved.
Here we go
So now we want, those different objects to share the same age.
Then that why we need to make use of prototype.
For a prototype we need to access it keyword from the class name.
Class name dot prototype , i believe it should be like this.
Then we have prototype, it will allow age to be shared among all other objects.
Now we don't need this thing over here
inheritance.