javascript - 为什么 Number.prototype 是一个数字

标签 javascript ecmascript-5

({}).toString.call(Number.prototype) === "[object Number]"

The Number prototype object is itself a Number object (its [[Class]] is "Number") whose value is +0.

15.7.4

为什么 Number.prototype 是一个数字会有用? (对于所有其他 [[Class]] 设置为非 Object 的内置原型(prototype)也是如此)

我选择 Number.prototype 特别是因为我可以想象 Array.prototypeDate.prototype 的合理遗留原因。

最佳答案

通常,Constructor.prototypeConstructor 定义的“类型”的范例。尽管对于不可 rebase 元来说事情似乎变得棘手,尤其是当你涉及到装箱的东西时,这个范例概念仍然有意义,0Number 的“范例”。

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

相关文章:

javascript - 使用 Three.js 程序生成粒子纹理

javascript - 纽约市与 webpack 4 使用 .tmp 文件夹

javascript - 如何使用 Jquery JS Cookie 检索 Cookie 值

javascript - 澄清 Typescript 的目标和库设置的功能

javascript - 为什么我们需要 isPrototypeOf 呢?

javascript - splat over JavaScript 对象(用 new )?

javascript - 如何使用单选按钮更改 <td> 的颜色?

javascript - 提取部分 JSON 对象结果

javascript - 兼容 ES6 功能

javascript - 从 url 中批量删除所有查询字符串?