js原型继承继承构造器带来的缺点
- 修改Person构造器会影响到继承他的子类
function Person(){this.sex = 'man'};
function Man(){};
Man.prototype = Person;
var m1 = new Man();
m1.sex;//'man'
// 修改Person构造器会影响到继承他的子类
delete Person.sex;
m1.sex;//undefined
js原型继承继承构造器实例避免缺点
function Person(){this.sex = 'man'};
function Man(){};
Man.prototype = new Person();
Man.prototype.construct = Man;
var m1 = new Man();
m1.sex;//'man'
// 修改Person构造器不会影响到继承他的子类
delete Person.sex;
m1.sex;//'man'