On Mon, Oct 6, 2014 at 10:48 PM, Dmitry Soshnikov <
[email protected]> wrote:

> On Mon, Oct 6, 2014 at 8:19 PM, Rick Waldron <[email protected]>
> wrote:
>
>>
>>
>> On Mon, Oct 6, 2014 at 10:59 PM, Dmitry Soshnikov <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>> We're currently polyfilling `Array.from` in our codebase following the
>>> latest draft [1]. And I was actually surprised by the `mapfn` being
>>> involved into the algorithm.
>>>
>>
>> Have you tried es6-shim?
>>
>>
>
> Yeah, I'm aware of it, though, we have own versions for better
> performance, since may skip some internal checks, etc.
>
>
>>
>>> I mean, from the performance perspective it's probably .. ok-ish.. but
>>> from the API design perspective it feels like combining the actual
>>> transformation of an iterable (or of an array-like) with the mapping, is
>>> the "too much of responsibility" anti-pattern. Why not filter then as well?
>>> (or, as one of the comments on a diff review: "I'm actually
>>> disappointed it won't do my laundry as well :P").
>>>
>>> It probably should be just:
>>>
>>> ```
>>> Array.from(...).map(mapfn);
>>> ```
>>>
>>> Unless I'm missing something, and there was a special reason to include
>>> the mapping.
>>>
>>
>> Yes:
>> https://github.com/rwaldron/tc39-notes/blob/c61f48cea5f2339a1ec65ca89827c8cff170779b/es6/2013-01/jan-30.md#revising-the-array-subclassing-kind-issue
>> Any subclass of array will want to produce a list of its own "kind", but
>> .map returns an Array. This thread is also a dup of:
>> https://mail.mozilla.org/pipermail/es-discuss/2013-June/031500.html
>>
>>
> I see. OK, thanks Rick, will re-read.
>

OK, have checked. And guess I still don't see a big issue, as long as the
`Array.prototype.map` preserves the kind (by delegating to `new
this.constructor(...)`).

That specific example like:

```
NodeList.form(['div', 'span'], nodeName =>
document.createElement(nodeName));
```

arguing that the `NodeList` can't create elements from the strings doesn't
seems to me a good reason for introducing that anti-pattern, and it's
really should be rewritten as:

```
NodeList.form(['div', 'span'].map(nodeName =>
document.createElement(nodeName)));
```

And other things are better be written:

```
<ArrayKind>.from(iterable).map(mapfn)
```

Am I still missing something?

Dmitry
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to