原理很简单,就是沿着原型链往上查找
function myInstanceof(target, obj){if(typeof target !== "object" || target === null) return false;// 往上找target的原型let proto = target.__proto__// let proto = Object.getPrototypeOf(target);while(true){//查找到尽头,还没找到if(proto == null) return false;if(proto == obj.prototype) return true;// 向上查找proto = proto.__proto__// proto = Object.getPrototypeOf(proto);}
}