Instanceof Determines the data type

XXX instanceof XXx2 XXX to the base class prototype chain is not xxx2 shadow

All reference datatypes instanceof Object are true

All value types instanceof are false

Implement a myInstance yourself

   functionMyInstance (temp, classN) {//temp looks up from __proto__ // if __proto__ === classn. prototype returnstrue// when __proto__===null; returnfalse
        let str = typeof temp;
        if(str ! = ='object'&& str ! = ='function') return false;
        var left = temp.__proto__,
            right = classN.prototype;
        // if (left === right) return true;
        while (left) {
            if (left === right) return true;
            left = left.__proto__;
        }
        return false;
    }

    functionInstance_of (L, R) {//L stands for left expression, R stands for right expression var O = r.protoType; // take the display prototype of R L = l.__proto__; // take the implicit prototype of Lwhile (true) {
            if (L === null) return false;
            if(O === L) // Key here: return if O is strictly Ltrue
                return true;
            L = L.__proto__;
        }
    }
    [] instanceof Array; //true
    [] instanceof Object; //true
    [] instanceof Number; //false
    1 instanceof Number; //false

    myInstance([], Number); 

Copy the code