JavaScript isPrototypeOf vs instanceof usage

前端 未结 5 1263
清歌不尽
清歌不尽 2020-12-13 09:08

Suppose we have the following:

function Super() {
      // init code
}

function Sub() {
      Super.call(this);
      // other init code
}

Sub.prototype =          


        
5条回答
  •  抹茶落季
    2020-12-13 09:54

    var neuesArray = Object.create(Array);
    
    Array.isPrototypeOf(neuesArray);            // true
    neuesArray instanceof Array                 // false
    neuesArray instanceof Object                // true
    Array.isArray(neuesArray);                  // false
    Array.prototype.isPrototypeOf(neuesArray);  // false
    Object.prototype.isPrototypeOf(neuesArray); // true
    

    Do you understand my friend :) - is simple

提交回复
热议问题