typeof determine whether the correct type? instanceof it? The principle instanceof What is?

instanceof implementation code:

// L R the instanceof 
function instance_of (L, R) { // L denotes a left expression, R represents the right expression 
    var O = R.prototype; // Explicit Prototype take the R 
    L = L .__ proto__;     // get L implicit prototype 
    the while ( to true ) { 
         iF (L === null ) // have found top 
            return  to false ;  
         iF (O === L)    // when exactly equal to O L, returns to true 
            return  to true ; 
        L = .__ proto__ L;   // continue to look up one prototype chain 
    } 
}

First typeof possible to determine the basic data types, but in addition to null, typeof null is returned object

But the object is not accurately determine the type typeof, typeof function returns function, are all in addition to object, it can not accurately determine the type

instanceof based on complex data types, data types can not be substantially

instanceof is judged by the prototype chain, instanceof A B, in a prototype look layer in chain A, whether or not there is equal to the prototype B.prototype, if the prototype has been found to the top of chain A (null, i.e. Object.prototype._proto_), still not equal to B, then returns false, true otherwise

Guess you like

Origin www.cnblogs.com/nini123123/p/10994423.html