//递归实现instanceOf //其作用是检测fucntion.prototype是否存在于对象的原型链上 const instanceOfTest = (obj,fn)=>{ //必须是具备原型的 if(obj && !['object','function'].includes(typeof obj)){ return false } //实例对象的原型 const proto = Object.getPrototypeOf(obj) if(proto === fn.prototype){ return true }else if(proto === null){ return false }else{ return instanceOfTest(proto,fn) } } function Cat(name){ this.name = name } function Test(name){ this.name = name } const dot = new Cat("blank") console.log(instanceOfTest(dot,Test))