function fn(){
this.a = 0;console.log(this);this.b = function(){console.log(this.a);
}}
fn.prototype = {
b:function(){this.a = 20;console.log(this.a);
},c:function(){this.a = 30;console.log(this.a);
}}
var myfn = new fn();
myfn.b();
myfn.c();
这段代码输出的是0 和 20;
为什么后面的a = 20没有将前面的a = 0覆盖呢?
还有fn里面的this 指向的是谁呢?
噜噜哒
红颜莎娜
随时随地看视频慕课网APP
相关分类