简体   繁体   中英

Why is Number.prototype a Number

({}).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

Why would it be useful for Number.prototype to be a Number? (the same goes for every other built-in prototype which has the [[Class]] set to not Object)

I'm picking on Number.prototype specifically because I can imagine sensible legacy reasons for Array.prototype and Date.prototype .

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

Why wouldn't Number.prototype be a Number object? Its [[Prototype]] is Object.prototype, so it still inherits from Object.

In general, Constructor.prototype is an exemplar of the "type" defined by Constructor . Although things seem to get hairy for immutable primitives, and especially once you involve the boxing stuff, this exemplar concept still makes sense, with 0 being the "exemplar" of Number .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM