js instanceof 实现原理

function instanceof(left, right) { // 得到类型的原型
    let prototype = right.prototype // 得到对象的原型
    left = left.__proto__ // 判断对象的类型是否等于类型的原型
    while (true) { if (left === null) return false
        if (prototype === left) return true left = left.__proto__ } }

//原理:对象的原型链中是否是能找到类型的 
prototype
相关文章
相关标签/搜索