instanceof 运算符简介 在 JavaScript 中,判断一个变量的类型尝尝会用 typeof 运算符,在使用 typeof 运算符时采用引用类型存储值会出现一个问题,无论引用的是什么类型的对象,它都返回 "object"。ECMAScript 引入了另一个 Java 运算符 instanceof 来解决这个问题。instanceof 运算符与 typeof 运算符相似,用于识别 ...
instanceof的工作原理就是测试构造函数的prototype 是否出现在被检测对象obj的原型链上。 注意:instanceof 也不是万能的。 举个例子: let arr = [] let obj = {} arr instanceof Array // true arr instanceof Object // true obj instanceof Object // true obj ...
Left: Data to check Right: Data type (Array, Object, etc.) Returns true if it is the specified type itself or its parent/ancestor Returns false if a child or descendant type is specified Very useful ...
一些您可能无法访问的结果已被隐去。
显示无法访问的结果