function instanceOf(target, type) {
type = type.prototype
target = target.__proto__
while(true) {
if(target === null) {
return false
}
if(target === type) {
return true
}
target = target.__proto__
}
}
let arr = [1, 2]
console.log(instanceOf(arr, Array)) // true
console.log(instanceOf(arr, Object)) // true
实现 instanceof
最新推荐文章于 2022-09-15 16:52:03 发布