function _instanceof (instance, constructor) {
if (typeof constructor !== 'function') {
throw new TypeError(`Right-hand side of 'instanceof' is not callable`)
}
const isPrimitive = (value) => value == null || (typeof value !== 'object' && typeof value !== 'function')
const constructorPrototype = constructor.prototype
let prototype = instance
while (!isPrimitive(prototype)) {
prototype = Object.getPrototypeOf(prototype)
if (prototype === constructorPrototype) return true
}
return false
}
定义
检测构造函数的
prototype
属性是否出现在某个实例对象的原型链上。实现
F.prototype
的原型