Why does Array.from also take a mapFn?

Brandon Benvie bbenvie at mozilla.com
Mon Jun 24 09:45:00 PDT 2013


On 6/24/2013 9:44 AM, Brandon Benvie wrote:
> On 6/24/2013 9:42 AM, Domenic Denicola wrote:
>>> That led to further discision of that usage and we got into things 
>>> like the last example:
>>>
>>> ```js
>>> // Turn an array of nodeNames into NodeList of nodes
>>> NodeList.from( ["div"], node => document.createElement(node) );
>>> ```
>> I think I must be missing something. Why is this superior to
>>
>> ```js
>> NodeList.from(["div"].map(node => document.createElement(node));
>> ```
>
> Using `NodeList.from` returns a NodeList. NodeList.from(...).map(...) 
> returns an Array.

Sorry I misread it! I see your point.


More information about the es-discuss mailing list