function a(){
this.hello=function(){
alert("hello!");
}
}a.prototype={
fuck:function(){
alert("oh fuck!");
},
hello:function(){
alert("hello 2!");
}
}var b=new a();
b.fuck(); //oh fuck!
b.hello();//hello! 这里hello 没有被 a.prototype.hello 覆盖为何?
/*
也就是说 this.hello 并不是 prototype 成员,那么 this.hello 是什么呢?
还有 var b=new a() 这个b 是什么?我以前一直以为 b 就是 a.prototype 的一个 副本
看来我错了
*/
this.hello=function(){
alert("hello!");
}
}a.prototype={
fuck:function(){
alert("oh fuck!");
},
hello:function(){
alert("hello 2!");
}
}var b=new a();
b.fuck(); //oh fuck!
b.hello();//hello! 这里hello 没有被 a.prototype.hello 覆盖为何?
/*
也就是说 this.hello 并不是 prototype 成员,那么 this.hello 是什么呢?
还有 var b=new a() 这个b 是什么?我以前一直以为 b 就是 a.prototype 的一个 副本
看来我错了
*/
首先找自身作用域,找hello,this.hello就是自身的,
如果自身没有找到就找prototype的hello所以b.hello()弹出来的不是alert("hello 2!");因为自身有这个值,就不去prototype找了