继承(共享原型)
缺点:son和father原型互相影响
Father.prototype.lastName = 'deng';
function Father(){
}
function Son(){
}
function inherit(Target,Origin){
Target.prototype = Origin.prototype;
}
inherit(Son,Father);
var son = new Son();
继承(圣杯模式)
function inherit(Target, Origin) {
function F() { };
F.prototype = Origin.prototype;
Target.prototype = new F();
Target.prototype.constuctor = Target;
Target.prototype.uber = Origin.prototype;
}
Father.prototype.lastName = 'deng';
function Father() {
}
function Son() {
}
inherit(Son, Father);
var son = new Son();
var father = new Father();
继承的应用
function Deng(name,wife){
var peraperWife = 'xz';
this.name = name;
this.wife = wife;
this.divorce = function (){
this.wife = peraperWife;
}
this.changePeraperWife = function(target){
peraperWife = target;
}
this.sayPeraperWife = function(){
console.log(peraperWife);
}
}
var deng = new Deng('deng','xl');