A instanceof B, A是否在B的原型链上

    1. const new_instanceof = function (instance, constructor) {
    2. let instance_proto = instance.__proto__;
    3. let constructor_proto = constructor.prototype;
    4. while(true) {
    5. // 找到终点返回false
    6. if (instance_proto === null) {return false};
    7. // 找到返回true
    8. if (instance_proto === constructor_proto) {return true};
    9. // 当实例与构造函数原型不相同, 沿着原型链继续向上查找
    10. instance_proto = instance_proto.__proto__;
    11. }
    12. }
    13. console.log([] instanceof Array) // true
    14. console.log(new_instanceof([], Array)) // true