Skip to content Skip to sidebar Skip to footer

Resetting The Constructor Property Of Prototype Object

Consider the following snippet: function shape(){ this.name = '2d shape' } function triangle(){ this.name = 'triangle'; this.ttest = function(){ alert('in tria

Solution 1:

Why do i get the shape constructor?

Note that et.constructor is a property inherited by the prototype:

et.constructor; // shape
et.hasOwnProperty('constructor'); // false

Then, .constructor is inherited from equitriangle.prototype.

But also note that equitriangle.prototype.constructor is inherithed from triangle.prototype.

But also note that triangle.prototype.constructor is inherithed from shape.prototype.

Finally, shape.prototype.hasOwnProperty('constructor') is true

Post a Comment for "Resetting The Constructor Property Of Prototype Object"