instanceof 运算符

  typeof 去判断一个变量的类型,是大家常用的,那么instanceof呢,看看的优势

  var a =‘hellow word’

  typeof(a)       //string

  a instanceof string //true 看不到优势

 

 

 instanceof 在多层继承关系中的优势

   function a(){}

   function b(){}

    a.prototype=new b()

   var a1=new a()

 a1 instanceof a   //true

a1 instanceof b    //true

 

posted @ 2017-10-16 16:07  cnblogs/yinbin  阅读(122)  评论(0)    收藏  举报