子类:
function child(){
this.childattr="childattr";
father.call(this);
}
function createnewobj(prototype){
function newobj(){}
newobj.prototype=prototype;
return new newobj();
}
child.prototype=createnewobj(father.prototype);
child.prototype.childprivate="childprivate";
子类也可以写成一个函数:
function createchild(){
function child(){ //借用构造函数继承
this.childattr="childattr";
father.call(this);
}
function createnewobj(prototype){
function newobj(){}
newobj.prototype=prototype;
return new newobj();
}
child.prototype=createnewobj(father.prototype);//原型继承
child.prototype.childprivate="childprivate";
return new child();
}
var child1=createchild();
console.info(child1.fathercommon);