当前位置:首页 > 网络编程 > 软件语言 > .NET > javascript中类的继承

javascript中类的继承

点击次数:43 次 发布日期:2008-11-06 07:53:12 作者:源代码网
源代码网推荐
广告载入中

源代码网整理以下<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
    function Movie(id,name,age)
    {  
        //私有属性
        var age=age;
        //公有属性
        this.ID=id;
        this.Name=name;
        SayYes=function(words)//私有方法
        {
            document.write(words);
            document.write("Age:"+age);
        }
        this.ShowInfo=function(words)//公有方法


        {  
            SayYes(words);
            document.write("ID: "+this.ID+"|Name: "+this.Name+"<br />");
        }
    }
    Movie.prototype.SayHello=function(words)
    {
        alert(words);
    }
   
   
    function Animal(sex,age)//基类
    {
        this.Sex=sex;
        this.Age=age;
    }
    function People(id,name,sex,age)//子类
    {
        //People.prototype=new Animal();
        this.ID=id;
        this.Name=name;
        this.Sex=sex;
        this.Age=age;
       
        this.Say=function()
        {
            document.write("ID:"+this.ID+"|Name:"+this.Name+"|Sex:"+this.Sex+"|Age:"+this.Age);
        }
    }
    People.prototype=new Animal();
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <script type="text/javascript">
        var a=new Movie(1,"abc",10);
        a.ShowInfo("Yes");
        a.SayHello("Hello");
       
        var b=new People(1,"a","男",10);
        b.Say();
    </script>
    </div>
    </form>
</body>
</html>


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华