js中.instanceof 的原理是什么?【面试题详解】

今天爱分享给大家带来js中.instanceof 的原理是什么?【面试题详解】,希望能够帮助到大家。


function myInstanceof(left, right) {
  let prototype = right.prototype
  left = left.__proto__
  while (true) {
    if (left === null || left === undefined)
      return false
    if (prototype === left)
      return true
    left = left.__proto__
  }
}
思路:
首先获取类型的原型
然后获得对象的原型
然后一直循环判断对象的原型是否等于类型的原型,直到对象原型为 null,因为原型链最终为 null

原文链接:https://blog.itblood.com/4637.html,转载请注明出处。
0
姨妈侠v0.040 AI版[PC+安卓/3.84G/更新]AuntMan [v0.040] [欧美SLG/汉化/动态]
姨妈侠v0.040 AI版[PC+安卓/3.84G/更新]AuntMan [v0.040] [欧美SLG/汉化/动态]
8分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?