function myNew(){
var constructor = [].shift.call(arguments),
_this = {};
_this.__proto__ = constructor.prototype;
var res = constructor.apply(_this,arguments);
return return typeof res === 'object' ? res : _this;
}
function instanceof(target,type){
// target 实例化对象 type 构造函数
type = type.prototype;
target = target.__proto__;
while(true){
if(target === null){
return false;
}
if(target === type){
target = target.__proto__;
}
}
}
手写new,instanceof方法
于 2022-12-22 15:36:10 首次发布