// 寄生函数
function obj(o){
function Fn(){};
Fn.prototype = o; // 把指针转回给自己
return new Fn();
}
function create(o,oBj){
var _o = obj(o.prototype);
_o.constructor = oBj;
oBj.prototype = _o;
return _o;
}
function B(name,age){
this.name = name;
this.age = age;
}
B.prototype.run = function(){
return this.name + this.age;
}
function D(name,age){
B.call(this,name,age);
}
create(B,D);
var box = new D('gaga',236);
console.log(box.constructor)
js寄生函数
最新推荐文章于 2022-08-16 16:28:57 发布