Note:- Each and every object, which we ever create is an instance of object constructor which has bunch of methods in its prototype property.
Now, let’s go ahead and add method to the constructor like shown below.
However, let’s suppose, we don’t have method attached to constructor but later on I would like to attach to it and use the same while creating new object. In that case, we can make use of prototype property like shown below.
At this instant also, it will create the same result like shown below.
Now, let’s go ahead inspect other properties in the object. Therefore, when I type Tom in the browser, it presented me below stuff.
And one of the important things are __proto__ as highlighted above. This is basically prototype of the Tom object which is prototype property of Employee Constructor.
Here you can see the method, which I have added in the function prototype later. We can also inspect a function constructor’s prototype as shown below. Here, It will show the complete list and type of that. Here, we have only one, hence only one is showing.
And to confirm that prototype of Tom is the prototype of Employee, we can test something like shown below.
Now, to prove the point all of the objects are basically inherited from object itself, we can traverse in prototype chain.
And, here we have bunch of methods which are basically associated with object Function Constructor.
Which means via prototype chain, these object’s method will also be available at our Employee object which is Tom here. Let’s one of these to prove the point.
Here, I have tested whether Desig belongs to Employee object or not, hence it gave true. However, I have also tested for something which is not part of Employee and here it gave false. We can also test whether Tom is object of Employee like
With this I would like to wrap this post here. In coming section, we will delve further. Till then stay tuned and happy Coding.
531 total views, 1 views today