继承方法-->原型的相互引用
function Father(){} Father.prototype.name = 'zhang'; function Son(){} function inherit(Target,Orgin){ Target.prototype = Orgin.prototype; } inherit(Son,Father); var son = new Son(); var father = new Father; console.log(son.name); console.log(father.name); Son.prototype.sex = 'nan'; console.log(son.sex); console.log(father.sex);
由于prototype指向到同一个对象,所以无论谁改变了内在属性,
都会统一改变;
不能保持对象原型的独立性