1. <script>
    2. // 1. 创建一个组合式继承
    3. function Father(name, age) {
    4. this.name = name;
    5. this.age = age;
    6. this.list = [1, 2, 3];
    7. }
    8. Father.prototype.say = function() {
    9. console.log(this.name);
    10. }
    11. function Child(name, age) {
    12. // 借用构造函数
    13. Father.call(this, name, age);
    14. }
    15. // 2. 添加寄生式继承Object.create
    16. Child.prototype = Object.create(Father.prototype);
    17. // Child.prototype.__proto__ === Father.prototype; 产生原型的继承关系
    18. console.log(Child.prototype.constructor === Child); // false, 因为寄生式继承破坏了原来的原型关系
    19. // 3. 重新制定子类原型对象的构造函数
    20. Child.prototype.constructor = Child;
    21. var child = new Child('张三', 18);
    22. console.log('child', child);
    23. </script>