javascript - 为什么 Array.prototype 是一个数组?

标签 javascript prototype

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

为什么?

Array.isArray( Array.prototype )//真

developer.mozilla.org什么都不解释

最佳答案

您假设每个原型(prototype)都是一个 Object 是不正确的。

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

输出:

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

来自ECMAScript Language Specification - 15.4.4 Properties of the Array Prototype Object (强调我的)

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

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.

关于javascript - 为什么 Array.prototype 是一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23652338/

相关文章:

javascript - 覆盖 jquery 闭包中定义的函数

javascript - 此函数如何处理缺少的参数

javascript - 找不到 VueJS 元素引用

javascript - EcmaScript 5 Google TechTalk - 范围事故 1 示例

typescript ,是否可以向外部类原型(prototype)添加方法?

javascript - HTML5 视频加载时间

javascript - 在 JavaScript 中编写对象方法的最佳方式是什么?

javascript - 为什么对象原型(prototype)中的属性不能被对象修改?

javascript - 仅当 Javascript 中存在类时才允许监听器事件运行

javascript - 检查鼠标输入的元素内容