Javascript多重继承 [英] Javascript multiple inheritance

查看:113
本文介绍了Javascript多重继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以请求以下代码帮助。我试图理解多重继承不确定为什么它不起作用。 BTW下面如果是多重继承的代码。谢谢

can anyone please help with the below code. I am trying to understand multiple inheritance not sure why its not working. BTW below if the code for multiple inheritance. Thanks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>Test Doc</title>
    <script type="text/javascript">
    function classX(){
        this.messageX="this is X Message";
        this.alertX=function(){
            alert(this.messageX);
        };
    }
    function classY(){
        this.messageY="this is Y Message";
        this.alertY=function(){
            alert(this.messageY);
        };
    }
    function classZ(){
        classX.apply(this);
        classY.apply(this);
        this.messageZ="this is Z Message";
        this.alertZ=function(){
            alert(this.messageZ);
        };
    }
    var abjz=new classZ();
    objz.alertZ();
    abjz.alertX();
    </script>
</head>

<body>


</body>
</html>


推荐答案

你在alertZ的调用中错误拼写了abjz ()。

You misspelled "abjz" in the call to "alertZ()".

经过更正,代码工作正常,据我所知(两个警报显示,一个用于Z,一个用于X)。

With that corrected, the code works fine, as far as I can tell (two alerts show up, one for Z and one for X).

这篇关于Javascript多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆