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());
             //]>
  • 相关阅读:
    C++ Low level performance optimize
    简单find命令的实现
    数据结构学习之栈
    随机数的生成
    数据结构学习(一)
    C复习---动态内存分配
    (转)虚拟文件系统(VFS)浅析
    (转) 中断处理程序&中断服务例程
    Gradle系列教程之依赖管理
    Gradle系列教程之依赖管理
  • 原文地址:https://www.cnblogs.com/myssh/p/1614819.html
Copyright © 2011-2022 走看看