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));

 

posted on 2022-02-01 09:53  weakup  阅读(29)  评论(0编辑  收藏  举报