Allen Wirfs-Brock (2013-07-12T15:49:55.000Z)
domenic at domenicdenicola.com (2013-07-12T16:36:00.309Z)
On Jul 11, 2013, at 9:01 PM, Luke Hoban wrote: > Two questions on new `Number` APIs: > > 1) Is it intentional that `clz` is on `Number.prototype` instead of `Number`? Why? Generally, operations that operate upon a value of a specific type are expressed as instance methods. We see this all the time with regular objects but we also we see this in `String` where we have many methods that operate upon string values. For `Number` we have the `toFixed`, etc. methods that convert number values to strings. To me, `clz` seem like it fall into this category of method that operate upon instances of a specific type. For example, compare and contrast: ```js '00101000111100001111000011110000'.indexOf('1') // 2 0x28f0f0f0.clz() //2 ``` both use instance methods, applied to a primitive value, that report something about the structure of the value The (new) `is*` methods on the `Number` constructor are generally different in that they are predicates that test values that may not actually be numbers so they can't be `Number.prototype` methods. I think there is a stronger case to me made for `Math.clz(number)`. `Number.prototype` and `Math` both seem like plausible homes for `clz`. In the end, I placed it on `Number` prototype because it is an operation that is specific to a particular numeric encoding rather than an implementation of a general mathematical function. > 2) Is it intentional that `Number.toInteger(Infinity)` returns `true`? Huh? How's that? `Number.toInteger` is specified as the single step: > 1 Return ToInteger(number) and step 4 of the abstract operation ToInteger(number): > 4 If number is +0, -0, +∞, or -∞, return number.