instanceof

使用instanceof可以判断函数是否是一个变量的构造函数,如使用instanceof可以判断一个变量是否是array类型

1 var arr=[1,2,3];
2 arr instanceof Array;//true
3 typeof arr;//object  而typeof只能判断它是对象

instanceof的判断的原理就是:

沿着原型链去找这个对象的__proto__属性值是否与构造函数的prototype属性值相同

1 arr instanceof Object;//true

 

posted @ 2018-03-04 20:23  shuangcherry  阅读(128)  评论(0编辑  收藏  举报