手动实现instanceof

function instanceof1(left, right){
    if(typeof right !== 'function') throw new Error('instanceof1 error')
    let proto = left.__proto__;
    while(proto){
        if(proto === right.prototype){
            return true;
        }
        proto = proto.__proto__
    }
    return false;
}

 

posted @ 2022-03-01 15:20  小僵尸  阅读(19)  评论(0编辑  收藏  举报