JavaScript isPrototypeOf vs instanceof usage

前端 未结 5 1262
清歌不尽
清歌不尽 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:43

    According to this MDN Ref:

    isPrototypeOf() differs from the instanceof operator. In the expression object instanceof AFunction, the object prototype chain is checked against AFunction.prototype, not against AFunction itself.

提交回复
热议问题