function myInstance(instance,origin){ if(instance==null) return false if(typeof instance !=='function' && typeof instance !=='object'){ return false//值类型 } let tempInstance=instance while(tempInstance){ if(tempInstance.__proto__==origin.prototype){ return true//匹配上了 } tempInstance=tempInstance.tempInstance__proto__//顺着原型链查找 } return false } console.log(myInstance([],Array)) console.log(myInstance([],Object)) console.log(myInstance({},Object)) console.log(myInstance({},Array))