SOURCE

function Parent(text){
    this.text=text;
    this.name=['xiaoming','xiaohong'];
}

Parent.prototype.getName=function(){
    console.log(this.text);
    console.log(this.name);
}

function Childern(text){
    Parent.call(this,text);
}

Childern.prototype=new Parent();
Childern.prototype.constructor=Childern;

let ch01=new Childern('i am ch01');
console.log(ch01.getName());
ch01.name.push('xiaodeng');
console.log(ch01.getName());
let ch02=new Childern('i am ch02');
console.log(ch02.getName());

/**
 * 优点:融合了原型链和构造函数的有点,是js里最常用的继承方式
 * 缺点:调用两次Parent构造函数
 */
console 命令行工具 X clear

                    
>
console