使用instanceof检测对象实现
作者:互联网
function User(){} function Admin(){} Admin.prototype=Object.create(User.prototype); let hd=new Admin(); console.log(hd instanceof Admin); console.log(hd instanceof User); //自定义写instanceof function checkPrototype(obj,constructor){ if(!obj.__proto__) return false; if(obj.__proto__==constructor.prototype) return true; return checkPrototype(obj.__proto__,constructor); } console.log(checkPrototype(hd,User));
标签:instanceof,__,obj,Admin,检测,对象,User,hd 来源: https://www.cnblogs.com/yyy1234/p/15858869.html