手写instanceof

155 阅读1分钟
function myInstanceof(L, R) {
    var prototype = R.prototype;
    proto = L.__proto__;
    while (true) {
      if (proto === null) {
        return false;
      }
      if (proto === prototype) {
        return true;
      }
      proto = proto.__proto__;
    }
  }