实现instanceof

69 阅读1分钟
function myInstanceOf (instance, target) {
            if (instance === null) return false // 一直找到null的时候,说明instance的原型链上真没target这个玩意,直接返回false
            if (instance === target.prototype) return true // 在原型链上找到了目标就返回真
            return myInstanceOf(Object.getPrototypeOf(instance), target) // 没找到,就继续在instance的原型上去找
        }