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());
             //]>
  • 相关阅读:
    Framework7-Vue搭建项目
    在vue中使用handsontable
    electron-vue中关闭烦人的es语法检查
    今天工作整整一个月了,来记录一下(web前端)
    在electron-vue项目中使用element-ui
    使用electron-vue搭建桌面应用程序项目
    Electron是个啥?
    2月11日-寒假进度11
    2月10日-寒假进度10
    2月9日-寒假进度09
  • 原文地址:https://www.cnblogs.com/myssh/p/1614819.html
Copyright © 2011-2022 走看看