js实现instanceof
关于instanceof的具体用法和原理,可参考:https://blog.csdn.net/LL18781132750/article/details/81115081
下面给出instanceof的实现代码:
function myInstanceof(left,right){
var proto = left.__proto__;
var protoType = right.prototype;
while(true){
if(proto === null){
return false
}
if(proto == protoType){
return true
}
proto = proto.__proto__
}
}