Object.entries in 2015

Jordan Harband ljharb at gmail.com
Tue Apr 14 09:32:13 UTC 2015


The other motivation might be subclasses - MyArray.from creates a MyArray,
MyMap.from would create a MyMap.

On Tue, Apr 14, 2015 at 2:03 AM, Leon Arnott <leonarnott at gmail.com> wrote:

> > 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]])`.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150414/e7970e75/attachment.html>


More information about the es-discuss mailing list