function instance_of(L,R){
const baseType = ['string','number','boolean','undefined','null','symbol'];
if(baseType.includes(typeof L)) { return false }
let RP = R.prototype;
let Lp = L.__proto__;
while(true){
if(Lp === null){
return false;
}
if(Lp === RP){
return true;
}
Lp = Lp.__proto__;
}
}
function person(name){
this.name = name;
}
var children = new person('小孩');
console.log(instance_of(children,person)); //true
console.log(children instanceof person); //true
手写instanceof,判断对象之间关联性
最新推荐文章于 2022-04-04 18:35:53 发布
关键词由CSDN通过智能技术生成