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ㄒ)/~~
添加回答
举报
0/150
提交
取消