zoukankan      html  css  js  c++  java
  • JavaScript面向对象之——继承【原】

      本列子参照JavaScript核心技术一书略作修改,JS中继承还远不止于此,本博只略作讲解

    JS-Code//<![CDATA
            //基类
            function tune(title,type,test)
            {
                this.title = title;
                this.type = type;
                this.getTitle = function(){
                    return "Song: " + this.title +" Type:" + this.type;
                }
            }
            //派生类
            function artist_tune(title,type,artist,test)
            {
                this.artist = artist;
                this.toString("Artist is"+artist);
                tune.call(this,title,artist);//call继承需列出参数
    //            tune.apply(this,arguments);//apply直接使用参数列表,不包含最后一个参数,也就是说title,type,artist,test只取前三个参数
                this.toString = function(){
                    return "Artist :"+this.artist+" "+this.getTitle();//调用继承基类的方法
                }
            }
           
    //        artist_tune.prototype = new tune();
            var song = new artist_tune("I want to hold your hand ","rock","Beatles","test");
            alert(song.toString());
             //]>
  • 相关阅读:
    rdlc报表动态生成实例
    动态分页实现
    多文件上传
    文件压缩
    javascript解决中文传递乱码和特殊字符问题
    rdlc报表动态生成公共类
    SQLHelp类
    验证码
    使用bison和yacc制作脚本语言(3)
    C Mingw gcc printf 刷新缓冲行
  • 原文地址:https://www.cnblogs.com/myssh/p/1614819.html
Copyright © 2011-2022 走看看