js 手写instanceof
o instanceof Ctor 判断对象o是不是构造函数Ctor生产的实例,原理是判断构造函数的原型是不是位于实例原型链或父级原型链上
const _instanceof = (o,Ctor)=>{
if(o === null) return false
let proto = Object.getPrototypeOf(o)
let prototype = Ctor.prototype
while(true){
if(!proto) return false
if(proto === prototype) return true
proto = Object.getPrototypeOf(proto)
}
}
console.log(_instanceof(new Date(),Array))
console.log(_instanceof(new Date(),Object))