js instanceof运算符

a instanceof B;

instanceof检测对象a的原型链中有没有构造函数B.prototype

如下:

function In (a, B) {

  var p = a.__proto__;

  if (p != null ) {

    if(p == B.prototype) {

      return true;

    }

    p = p.__proto__;

  }

  return false;

}

posted @ 2016-07-07 10:36  fly不起来啊!  阅读(144)  评论(0编辑  收藏  举报