JavaScript继承模式
继承发展: 1.传统形式 ————> 原型链 过多的继承了没用的属性 2.借用构造函数 不能继承借用构造函数的原型 每次构造函数都要多走一个函数 栗子: function Person(name, age, sex) { this.name = name; this.age = age; this.sex = sex; } function Student(name, age, sex, grade) { Person.call(this, name, age, sex); } var student=new Student(); 3.共享原型 不能随便改动自己的原型 栗子: 1. Father.prototype.lastName = 'Deng'; function Father() {} function Son() {} // 一个原型给了两个函数 Son.prototype = Father.prototype; var father = new Father(); function inherit(Target, Origin) { Target.prototype = Origin.prototype; } inherit(Son, Father); // 先继承后调用 var son = new Son(); 4.圣杯模式 栗子: 1. function