模拟instanceof实现

/**
* 模拟instanceof
*/
const simulateInstanceof = (L, R) => {
    // L表示左边表达式,R表示右边表达式
    const O = R.prototype; // 取R的显示原型
    L = L.__proto__; // 取L的隐式原型
    while (true) {
        if (L === null) {
            return false;
        }
        if (O === L) {
            return true;
        }
        L = L.__proto__;
    }
}

复制代码

参考资料

  1. www.cxymsg.com/guide/jsWri…

微信公众号“前端那些事儿”

发布了71 篇原创文章 · 获赞 43 · 访问量 79万+

猜你喜欢

转载自blog.csdn.net/cengjingcanghai123/article/details/104437403