Sunday, 15 September 2013

javascript two variables with same name co-exist in same object?

javascript two variables with same name co-exist in same object?

I'm trying my best to understand javascript. Here is a simple experiment
in Chrome console which gets me very confused:
var foo=function(){this.p=1;}
foo.prototype.p=2;
var bar=new foo();
//foo{p:1,p:2} <- this is the output of Chrome console, from the last
command above
Does this mean bar has 2 p??? What is the reasoning behind this?

No comments:

Post a Comment