
- yhuxAvNbtxUM
0000-00-00 00:00:00
- 回帖
functionextend(Child,Parent){varF=function(){};F.prototype=Parent.prototype;Child.prototype=newF();Child.prototype.constructor=Child;Child.uber=Parent.prototype;}functionShape(){}Shape.prototype.name='Shape';Shape.prototype.toString=function(){returnthis.constructor.uber?this.constructor.uber.toString()+','+this.name:this.name;};functionTwoDShape(){}extend(TwoDShape,Shape);TwoDShape.prototype.name='2Dshape';functionTriangle(side,height){this.side=side;this.height=height;}varF=function(){};extend(Triangle,TwoDShape);Triangle.prototype.name='Triangle';Triangle.prototype.getArea=function(){returnthis.side*this.height/2;};varShape=function(){};varTwoDShape=function(){};Shape.prototype.name='shape';Shape.prototype.toString=function(){returnthis.uber?this.uber.toString()+','+this.name:this.name;};extend(TwoDShape,Shape);vartd=newTwoDShape();td.name;//"shape"1.为什么说name属性既不会是TwoDShape()实例的属性,也不会成为其原型对象的属性,但是子对象依然可以通过继承方式来访问该属性?