JavaScript中子类调用父类方法

<html>
<head>
<title>sdfsad</title>
<meta content="text/html; charset=UTF-8"/>
<script type="text/javascript">


    Shape = function () {
        this.id = null;
        this.picture = null;
        this.draw = function (canvas) {
            this.picture = "由父类产生的图像已经生成在画布上了";
        };
    };


    
    //1
    CommonShape = function () { };
    CommonShape.prototype = new Shape();




    //2
    CrossFillShape = function () {
        this.draw = function (canvas) {
            CrossFillShape.prototype.draw.apply(this, arguments);
            this.picture = this.picture + ", 然后被子类 CrossFillShape 填充";
        };
    };
    CrossFillShape.prototype = new Shape();




    //3
    SolidFillShape = function () {
        this.draw = function (canvas) {
            SolidFillShape.prototype.draw.apply(this, arguments);
            this.picture = this.picture + ", 然后被子类 SolidFillShape 填充";
        };
    };
    SolidFillShape.prototype = new Shape();


    function test1() {
        alert("dasfd");
        var s = new CommonShape();
        s.draw();
        alert(s.picture);


        var cs = new CrossFillShape();
        cs.draw();
        alert(cs.picture);


        var ss = new SolidFillShape();
        ss.draw();
        console.debug(ss.picture);
    } 


</script>
</head>
<body>
<input type="button" value="test1" οnclick="test1()"/><br/>
</body>
</html> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值