在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 在《javascript面向?qū)ο蟆窌?shū)中uber-子對(duì)象訪問(wèn)父對(duì)象的方式的代碼報(bào)錯(cuò)

在《javascript面向?qū)ο蟆窌?shū)中uber-子對(duì)象訪問(wèn)父對(duì)象的方式的代碼報(bào)錯(cuò)

<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>
<div style="width:100px;height:100px;background:red;" onclick="myclick()"></div>
</body>
</html>

圖片描述

回答
編輯回答
陌上花

把this.constr.uber.toString() 改為 constr.uber.toString() 應(yīng)該就可以了

2018年1月4日 04:18