前端手写: 手写 instanceof

6 阅读1分钟
// 手写简单版 instanceof
function myInstanceof(left, rigth) {
  let proto = left.__proto__;
  let prototype = rigth.prototype;
  while (proto) {
    if (proto === prototype) {
      return true;
    }
    proto = proto.__proto__;
  }
  return false;
}

console.log(myInstanceof([1], Array))