手写instanceof 简单实现
1 | // instanceof 的原理 |
function myInstanceof(left, right) {
if (typeof left !== 'object' || right === null) {
return false
}
right = right.prototype
left = left__proto__
while (true) {
if (left === null) return false
if (left === right) return true
left = left.left__proto__
}
}
https://www.jiujue.top/2021/11/18/%E6%89%8B%E5%86%99instanceof-%E7%AE%80%E5%8D%95%E5%AE%9E%E7%8E%B0/
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 jiujue!
评论