要补充的内容是,在构造函数的prototype中,this代表着什么。
function Fn(){
this.name='小明';
this.year=1991;
}
Fn.prototype.getName=function(){
console.log(this.name);
}
var f1=new Fn();
f1.getName();//小明
如上代码,在Fn.prototype.getName函数中,this指向的是f1对象。因此可以通过this.name获取f1.name的值。
其实,不仅仅是构造函数的prototype,即便是在整个原型链中,this代表的也都是当前对象的值。