javascript 类 继承

<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>
posted @ 2008-05-14 04:16 楚暮四 阅读(195) 评论(1)  编辑 收藏 网摘 所属分类: Javascript

  回复  引用  查看    
#1楼 2008-05-14 10:33 | 簡簡單單..      
学习学习..

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索

相关文章:

相关链接: