简易实现 instanceOf

function instanceOf(left, right) {
    if (typeof left !== 'object' || left === null) {
        return false;
    }

    while(true) {
        if (left === null) {
            return false;
        }

        if (left.__proto__ === right.prototype) {
            return true;
        }

        left = left.__proto__;
    }
}

 

posted @ 2021-11-23 16:26  LeoX的爬坑笔记  阅读(34)  评论(0编辑  收藏  举报