玩笑过后

导航

组合继承

//父类
    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 );

 

posted on 2018-09-05 10:50  玩笑过后  阅读(61)  评论(0编辑  收藏  举报