A piece of code about how to implement 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__
    }
}

I feel like I made a fake front end two years ago, and I don"t understand the meaning of this code at all. Why do you set left=left.__proto__
outside the while and repeat it in the loop? Solve

Mar.14,2022

this is not a repeated setting. Each loop will check whether left is null and whether it is equal to prototype . If none of the conditions are true, then replace the left.__proto__ assignment left
with the following. In the first loop, the obj = left.__proto__ of the above if statement, if if When entering the second loop, obj = left.__proto__.__proto__ . Then cycle again and again until obj = null or obj = prototype ends.

  

on my knees. Thank you very much. Thank you very much. Thank you for saying nothing. Thank you

.
Menu