在《javascript面向对象》书中uber-子对象访问父对象的方式的代码报错
迷茫
迷茫 2017-04-11 09:19:48
0
1
341
<html>
<head>
<script>
function Shape() {}
// augment prototype
Shape.prototype.name = 'Shape';
Shape.prototype.toString = function () {
    var constr = this.constructor;
    return constr.uber
    ? this.constr.uber.toString() + ', ' + this.name
    : this.name;
};
function TwoDShape() {}
// take care of inheritance
var F = function () {};
F.prototype = Shape.prototype;
TwoDShape.prototype = new F();
TwoDShape.prototype.constructor = TwoDShape;
TwoDShape.uber = Shape.prototype;
// augment prototype
TwoDShape.prototype.name = '2D shape';
function Triangle(side, height) {
this.side = side;
this.height = height;
}
// take care of inheritance
var F = function () {};
F.prototype = TwoDShape.prototype;
Triangle.prototype = new F();
Triangle.prototype.constructor = Triangle;
Triangle.uber = TwoDShape.prototype;

// augment prototype
Triangle.prototype.name = 'Triangle';
Triangle.prototype.getArea = function () {
    return this.side * this.height / 2;
};
function myclick(){
    var my = new Triangle(5,10);
    console.log(my.toString());
}
</script>
</head>
<body>
<p style="width:100px;height:100px;background:red;" onclick="myclick()"></p>
</body>
</html>

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(1)
阿神

兄弟你好,请问你当年把这个问题解决了吗……我现在也卡在这儿了T0T

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板