function myInstanceOf(left, right) {
let prototype = right.prototype
let proto = Object.getPrototypeOf(left)
while(true){
if(!proto) return false
if(proto===prototype) return true
proto = Object.getPrototypeOf(proto)
}
}
console.log(myInstanceOf([], Array));//true
console.log(myInstanceOf(1, Array));//false
JS实现instanceOf()
最新推荐文章于 2022-05-10 15:34:23 发布