Array instanceof Array 为false Array instanceof Object 为true Object instanceof Object 为true
时间: 2024-05-22 07:16:35 浏览: 14
这是正确的。
第一个表达式返回false,因为Array是一个构造函数,而非一个实例对象,所以它不是一个数组的实例。
第二个表达式返回true,因为Array是Object的子类,所以它是一个对象的实例。
第三个表达式返回true,因为Object是一个构造函数,但同时也是它自己的实例。
相关问题
Array instanceof Array 为false Array instanceof Object 为true Object instanceof Object 为true 原因
:
Array instanceof Array 为false:因为Array是一个构造函数,它创建的实例是数组对象,而不是Array本身。因此,Array instanceof Array返回false。
Array instanceof Object 为true:因为Array也是一个对象,它是Object的子对象,因此,Array instanceof Object返回true。
Object instanceof Object 为true:因为Object是一个构造函数,它创建的实例也是对象,因此,Object instanceof Object返回true。
Array instanceof Array为false Object instanceof Object为true
这是因为在 JavaScript 中,Array 是一个特殊的对象类型,它继承自 Object。因此,Array 实例也是 Object 实例的一种,但是 Object 实例并不一定是 Array 实例。
当使用 instanceof 运算符来检查一个对象是否是某个类的实例时,它会检查该对象的原型链中是否存在该类的原型。如果存在,则返回 true,否则返回 false。
在本例中,Array instanceof Array 为 false,是因为 Array.prototype 不在 Array 的原型链上。而Object instanceof Object 为 true,是因为 Object.prototype 在 Object 的原型链上。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)