继承的三种方式

1、原型继承 (既继承了父类的构造器模板,又继承了父类的原型)

    // 原型继承
    // 既 继承了 构造器 ,又继承了 原型
    function Person(name,age) {
        this.name = name;
        this.age = age;
    }
    Person.prototype.id = 10;

    function Human(sex) {
        this.sex = sex;
    }
    Human.prototype = new Person("z3");
    var b1 = new Human("");
    alert(b1.name);         // z3        // 父类构造器里的属性
    alert(b1.id);           // 10        // 父类原型里的属性

2、类继承(只继承父类的构造器模板,不继承父类的原型)

    // 类继承
    // 只继承模板,不继承原型
    function Person1(name,age) {
        this.name = name;
        this.age = age;
    }
    Person1.prototype.id = 6;

    function Human1(sex,name,age) {
       this.sex = sex;
       Person1.call(this,name,age);
    }
    var b2 = new Human1("",'ls',15);
    alert(b2.name)                  // ls                // 父类构造器里的属性
    alert(b2.sex);                  //// 子类构造器里的属性
    alert(b2.id)                    // undefined         // 父类原型里的属性    未被继承

3、混合继承 (既继承了父类的构造器模板,又继承了父类的原型)

    //  混合继承  继承模板 + 原型
    function Person2(name,age) {
        this.name = name;
        this.age = age;
    }
    Person2.prototype.id = 8;
    Person2.prototype.sayName = function () {
        alert(this.name);
    }

    function Human2(sex,name,age) {
        this.sex = sex;
        Person2.call(this,name,age)
    }

    // 因为 在实例化父类模板的时候,并没有传参数,因此没有实例化 模板里的属性
    // 只继承了 父类的实例 的原型对象  因此并没有继承模板,只继承了原型
    Human2.prototype = new Person2();
    var b3 = new Human2("","z5",22);
    b3.sayName();                       // z5
原文地址:https://www.cnblogs.com/debra/p/7843768.html