Array的原型链上是否包含Array
时间: 2023-11-07 13:24:41 浏览: 34
的原型?
是的,Array的原型链上包含Array的原型。具体来说,Array的构造函数是Array(),它的原型是Array.prototype,而Array.prototype的原型是Object.prototype,因为所有的对象都是从Object.prototype继承而来的。因此,Array的原型链上包含了Object.prototype和Array.prototype。
相关问题
Object和Array的原型链
Object和Array都是JavaScript中的内置对象,它们都继承自Object.prototype。
Object.prototype是JavaScript中所有对象都会继承的原型对象,它包含了一些通用的方法和属性,比如toString()、valueOf()、hasOwnProperty()等等。
Array.prototype是Array对象的原型对象,继承自Object.prototype。它也包含了一些通用的方法和属性,比如push()、pop()、splice()等等,这些方法可以被Array对象所继承和使用。
在JavaScript中,当我们访问一个对象的属性或方法时,它会先在该对象本身查找,如果没有找到,就会去该对象的原型对象中查找,如果还是没有找到,就会去原型对象的原型对象中查找,一直到最终的Object.prototype。
因此,Object和Array的原型链可以表示为:
Object -> Object.prototype -> null
Array -> Array.prototype -> Object.prototype -> null
Array instanceof Array 为 false的原理
数组是一种特殊的对象,其原型链上除了 Object.prototype 还有 Array.prototype。Array instanceof Array 为 false 的原因是因为 instanceof 运算符会沿着原型链向上查找,判断一个对象的原型链上是否包含指定的构造函数,而数组的原型链上除了 Array 构造函数外还包含了 Object 构造函数,因此 instanceof 运算符在查找时会返回 false。换句话说,数组虽然是 Array 的实例,但它也是 Object 的实例,因此 instanceof 运算符不能完全识别它。
相关推荐
![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)