手撕intanceof

关于原型链可以去看https://chun53.top/266.html

直接上代码

const instanceof_ = (obj, newFn) => {
  //递归的方式
  if (typeof obj !== 'object' || typeof obj !== 'function') {
    return false
  }
  //Object.getPrototypeOf来获取隐式原型
  let proto = Object.getPrototypeOf(obj)
  if (proto === newFn.prototype) {
    return true
  } else if (proto === null) {
    return false
  } else {
    return instanceof_(proto, newFn)
  }
}


阅读剩余
THE END