手写instanceof的功能

instanceofJudge(data, value) {
  if (typeof data !== "object" || typeof value === null) {
     return false;
   }
   let proto = Object.getPrototypeOf(data);
   while (1) {
     if (proto == null) {
       return false;
     }
     if (proto == value.prototype) {
       return true;
     }
     proto = Object.getPrototypeOf(proto);
   }
 }

测试如下
在这里插入图片描述

发布了112 篇原创文章 · 获赞 33 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_40282732/article/details/105547850
今日推荐