Why is Array.prototype an array?

I thought that every prototype should be an object.

why?

Array.isArray (Array.prototype) // true

developer.mozilla.org doesn't explain anything

+1
source share
2 answers

Your assumption that every prototype is Objectwrong.

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

Output:

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

From ECMAScript Language Specification - 15.4.4 Properties of the Array Prototype Object (highlighted by me)

The value of the [[Prototype]] internal property of an Array prototype object is the standard built-in object of the prototype object (15.2.4).

- ; [[]] "", length ( +0) [[DefineOwnProperty]], 15.4.5.1.

+4

javascript: typeof Array.prototype;

Array.prototype . .

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype

, - , [] Array.

, Array.prototype []. Array.prototype.constructor function Array() { [native code] }

[].constructor function Array() { [native code] }

, , Array [].

, , .

-1

Source: https://habr.com/ru/post/1618701/


All Articles