关于子对象访问父对象的方式,看不明白第二步了,求大神解答下,多谢O(∩_∩)O

function Shape(){}
Shape.prototype.name="shape";
Shape.prototype.toString=function(){
   var const = this.constructor;
   return  const.uber? this.const.uber.toString()+","+this.name:this.name;
}
function TwoDShape(){}
var F=function(){};
F.prototype=Shape.prototype;
TwoDShape.prototype=new F();
TwoDShape.prototype.constructor=TwoDShape;
TwoDShape.uber=Shape.prototype;
TwoDShape.prototype.name="2D shape";

function Triangle(side,height) {
   this.side=side;
   this.height=height;
}
var F=function(){};
F.prototype=TwoDShape.prototype;
Triangle.prototype=new F();
Triangle.prototype.constructor=Triangle;
Triangle.uber=TwoDShape.prototype;
Triangle.prototype.name="Triangle";
Triangle.prototype.getArea=function(){
   return this.side*this.height/2;
};

var my=new Triangle(5,10);
my.toString();




my没有tostring方法,不断的向上找,找到shape的tostring方法,输出的第一个为this.const.uber.toString+,Triangle,接着就看不明白了,const里面有个this,前面还有个this,(这个this不多余么?)

有没有能把完整的过程解读下的大神,小弟跪谢了/(ㄒoㄒ)/~~



Geek喜多川
浏览 1806回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP