instanceof
本文最后更新于:7 个月前
实现instanceof
function MyInstanceof(l,r){
let Lproto = l.__proto__;
const Rproto = r.prototype;
while(Lproto){
if(Lproto === Rproto){
return true
}else{
Lproto=Lproto.__proto__;
}
}
return false;
}
class a {
constructor() {
this.a = 1;
}
}
let b= new a;
console.log(MyInstanceof(b,Object))
console.log(MyInstanceof(b,a))
console.log(MyInstanceof(b,Function))
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!