prototype是一个数组

prototype是一个数组

本文介绍了为什么Array.prototype是一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为每个原型都应该是一个对象。

I thought every prototype should be an object.

为什么?

Array.isArray(Array。原型)// true

Array.isArray( Array.prototype ) // true

什么都不解释

推荐答案

你的假设是每个原型是对象是不正确的。

Your assumption that every prototype is an Object is not correct.

console.log(String.prototype)
console.log(Number.prototype)
console.log(Boolean.prototype)
console.log(Array.prototype)
console.log(Object.prototype)

输出:

String {}
Number {}
Boolean {}
[]
Object {}

来自(强调是我的)

数组原型对象本身就是一个数组;它的[[Class]]是Array,它有一个length属性(初始值为+0)和15.4.5.1中描述的特殊[[DefineOwnProperty]]内部方法。

The Array prototype object is itself an array; its [[Class]] is "Array", and it has a length property (whose initial value is +0) and the special [[DefineOwnProperty]] internal method described in 15.4.5.1.

这篇关于为什么Array.prototype是一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:30