News for hackers. Stuff that matters.
Re:ECMAScript 2017 Language Specification by kevincennis on Tuesday July 11, 2017 @03:01PM (#14746981)
I believe that one of the main reasons not to do this is that adding anything to `Object.prototype` means that now everything inherits that new method.

So you have weird things like `'foo'.map()`, `( 42 ).map()`, `new WeakMap().map()`, `false.map()`, etc.

Re:ECMAScript 2017 Language Specification by radarsat1 on Tuesday July 11, 2017 @04:28PM (#14747765)
Those all sort of make sense to me.

'foo' is a string and can be iterated over.

42 is a number that can be provided to a function. Not sure about this one tbh. Could be useful for passing a number to a function if-and-only-if the number is valid (not NAN)

WeakMap(), I don't know what it is but I assume it's a map that can be iterated over.

mapping 'false' would fit well the Maybe monad.

Re:ECMAScript 2017 Language Specification by kevincennis on Tuesday July 11, 2017 @06:27PM (#14748628)
But what are the own properties of a number? There's nothing to iterate, and therefore nothing to map.

WeakMap is a new-ish type whose keys are objects. The references to those objects are weakly held, which means that an object `x` whose only reference is a WeakMap key will still be eligible for garbage collection. They are non-iterable for exactly that reason.

Also: how do you iterate over `false` or a function? What about user-created classes?

There are so many cases where the behavior would either be nonsensical or at least unintuitive that (in my personal and completely subjective opinion) they outweigh the slight convenience of being able to "map" a plain old JavaScript object.

Re:ECMAScript 2017 Language Specification by radarsat1 on Wednesday July 12, 2017 @09:42AM (#14752430)
No answer for WeakMap, and like I said, not sure about integers, but if you take a look at Haskell monads, you'll see that surprising things like Maybe (booleans, essentially, or rather container classes that either contain something or don't) can be iterated over. It's a very useful concept that abstracts somewhat the idea of "iterable", to "do something with all the things", where in the case of Maybe, all the things is either one thing or nothing.

Granted, in JavaScript maybe this wouldn't make sense.

Re:ECMAScript 2017 Language Specification by Jacqued on Tuesday July 11, 2017 @06:28PM (#14748631)
Actually WeakMap() could not be iterated over as its keys are not enumerable by design - you can't "know" at any given time what the list of keys actually contains.
Re:ECMAScript 2017 Language Specification by radarsat1 on Wednesday July 12, 2017 @09:37AM (#14752389)
Fair enough.