码迷,mamicode.com
首页 > 其他好文 > 详细

组合继承

时间:2018-09-05 11:11:54      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:book   style   cti   super   rip   color   class   htm   func   

//父类
    function superClass(name){
        this.name = name;
        this.books = [‘html‘,‘css‘,‘javascript‘];
    }
    superClass.prototype.getName = function(){
        console.log(this.name);
    }
    //子类
    function subClass(name,time){
        superClass.call(this,name);
        this.time = time;
    }
    
    subClass.prototype = superClass.prototype;
    subClass.prototype.getTime = function(){
        console.log(this.time);
    }
    var s1 = new superClass();
    var s2 = new subClass(‘klkx‘,2018);
    s2.books.push(‘vue‘);
    console.log( s2 );
    s2.getName();
    console.log( s2.books );
    console.log( s1.books );

 

组合继承

标签:book   style   cti   super   rip   color   class   htm   func   

原文地址:https://www.cnblogs.com/jokes/p/9590802.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!