Prototypal inheritance in java script
Hey i am a web developer but I want to add some extra skill to add my resume like mobile development, machine learning so what’s the solution of this. one of the solution is that i am adding these skill or Inherit these extra skills from my friend or senior who have these extra skills.
But what’s the reason of above discussion in terms of programming language, well the topic is that can i Inherit extra functionality in my existing object from another object in java script. This can be done by using the concept of Prototypal Inheritance in java script.
[Prototype]
In java script object have hidden property Prototype, that is either null
or references another object. That object is called “a prototype”:
Prototype is internal property, But we can set it using __proto__ .
Now in the above example we see that Lion has it’s own property and Kangaroo contains it’s own property. But what if i want to Inherit the property of Lion in Kangaroo Let’s see how to do this using __proto__
So we can see this from above example that now kangaroo inherits the property of the Lion also.
Please note that __proto__
is not the same as [Prototype]
. That’s a getter/setter for it.
Keep learning.