模拟实现 instanceof
js
function fakeInstanceof(left, right) {
const rightProto = right.prototype
// eslint-disable-next-line no-proto
let leftProto = left.__proto__
// eslint-disable-next-line no-constant-condition
while (true) {
if (leftProto === null) {
return false
}
if (leftProto === rightProto) {
return true
}
// eslint-disable-next-line no-proto
leftProto = leftProto.__proto__
}
}