1. 程式人生 > >組合繼承

組合繼承

組合繼承 get call new prototype name gettime log fun

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

組合繼承