Reputation: 3715
I have a function which I am using as a constructor. When I assign a function to it prototype and invoke the function, I only see the value x
and not the testMethod
which I augmented. I was expecting the augmented function also to be printed when i refer to the this
. Is my understanding correct.
function Test(x){
this.x=x;
}
Test.prototype.testMethod=function(){
console.log(this);
}
var t= new Test(5);
t.testMethod();
Upvotes: 0
Views: 53
Reputation: 87203
Because function testMethod()
is in the prototype, you cannot see it in the console. It is hidden in the __proto__
property.
If you expand __proto__
in your console, you'll see it.
Upvotes: 2