今天刚学完,还没弄懂.
//临时中转函数
function obj(o){
function F(){};
F.prototype=o;
return new F();
}
//寄生函数
function create(box,desk){
var f=obj(box.prototype);
f.constructor = desk;
desk.prototype=f;
}
//构造函数
function Box(name,age){
this.name=name;
this.age=age;
}
Box.prototype.run=function(){
return this.name+this.age+'运行中..';
}
//对象冒充
function Desk(name,age){
Box.call(this,name,age);
}
create(Box,Desk); //用来替代Desk.prototype=new Box();
var desk=new Desk('lee',100);
alert(desk.run());