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
相關文章
相關標籤/搜索