68 字
1 分钟
手写instanceof方法
function myInstanceof(left, right) { // 1.获取对象原型 let proto = Object.getPrototypeOf(left) // 2.获取构造函数的prototype对象 let prototype = right.prototype // 3.判断构造函数的prototype是否在该对象的原型链上 while(true) { if(!proto) return false if(proto === prototype) return true proto = Object.getPrototypeOf(proto) }} 手写instanceof方法
https://blog.oceanh.top/posts/frontend/手写instanceof方法/