I have following piece of code for learning JS.
function CircleArea(x)
{
this.x = x;
}
CircleArea.prototype =
{
area: function () {
return 22 / 7 * this.x * this.x;
}
};
var CalArea = new CircleArea(7);
if( CalArea.constructor === CircleArea.prototype.constructor)
{
alert(CalArea.area());
}
I decoupled the inheritance chain by assigning an object literal to CircleArea.prototype and then defined CalArea object using CircleArea constructor. Now both CalArea.constructor and CircleArea.prototype.constructor are basically Object constructors rather than CircleArea constructor but when I called CalArea.area() inside alert function this.x obtains 7 as its value whereas value 7 is passed as an argument to CircleArea constructor not to Object constructor to which CalArea.constructor and CircleArea.prototype constructors refer now.