定义:Instanceof 运算符用来判断一个构造函数的prototype属性所指向的对象,是否存在另一个要检测对象的原型链上
举例:
- Function instanceof Object
- 结果:true
- 原因:Function.proto.proto == Object.prototype.
- Object instanceof Function
- 结果:true
- 原因:Object.proto = Function.prototype
- {} instanceof Object
- 结果:true
- [] instanceof Array
- 结果:true
- [] instanceof Object
- 结果:true
- "123" instanceof String
- 结果:false
- new String(123) instanceof String
- 结果:true
- f instanceof Function (function f(){})
- 结果:true
- f instanceof Object (function f(){})
- 结果:true