Object.entries in 2015

Leon Arnott leonarnott at gmail.com
Tue Apr 14 09:03:45 UTC 2015


> The Map constructor takes an iterable of [key, value] pairs. Array.from
> takes an iterable of elements.This asymmetry is presumably because the
> Array constructor's behaviour is already defined. A hypothetical Map.from
> would merely be the same as the Map constructor!

Not quite true: Array.from, unlike every other iterable consumer in
the spec, also takes array-like plain objects: `Array.from({0:'E',
1:'S', 2:'6', length:3})` produces `["E","S","6"]`. The motivation for
Map.from is that you could feed it a "map-like object" (that is, an
object with no iterator) and get a Map in return: `Map.from({ foo: 1,
bar: 2 })` would behave as `new Map([['foo',1],['bar',2]])`.


More information about the es-discuss mailing list