On Wed, Oct 8, 2014 at 2:47 PM, Dmitry Soshnikov <dmitry.soshni...@gmail.com > wrote:
> > On Wed, Oct 8, 2014 at 2:42 PM, Dmitry Soshnikov < > dmitry.soshni...@gmail.com> wrote: > >> On Tue, Oct 7, 2014 at 4:08 PM, Claude Pache <claude.pa...@gmail.com> >> wrote: >> >> >>> Le 7 oct. 2014 à 23:43, Dmitry Soshnikov <dmitry.soshni...@gmail.com> a >>> écrit : >>> >>> On Tue, Oct 7, 2014 at 2:35 PM, Tab Atkins Jr. <jackalm...@gmail.com> >>> wrote: >>> >>>> On Tue, Oct 7, 2014 at 2:26 PM, Dmitry Soshnikov >>>> <dmitry.soshni...@gmail.com> wrote: >>>> > I see. Actually it doesn't work, your're correct, since >>>> > `Array.prototype.map` does preserve the kind (at least in the latest >>>> draft). >>>> >>>> Hmm, per Rick's earlier email and >>>> < >>>> https://github.com/rwaldron/tc39-notes/blob/c61f48cea5f2339a1ec65ca89827c8cff170779b/es6/2013-01/jan-30.md#revising-the-array-subclassing-kind-issue >>>> >, >>>> Array#map (used by a subclass) doesn't preserve the subclass's type; >>>> it always returns an Array. >>>> >>>> > And the `UInt32Array.from(...)` would be consuming a nodeList, not an >>>> array. >>>> > Will the `nodeList.map(node => parseInt(node.value, 10));` by itself >>>> > actually work then? >>>> >>>> If .map() is inherited from Array, and thus not type-preserving, yes, >>>> it'll work. >>>> >>>> >>> Yes, it is preserving (probably was changed since that previous >>> discussion), see (9) in >>> http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.map. >>> Will a simple map to `node.value` on a `NodeList` work with the preserving >>> `Array#map`? >>> >>> >>> So, a `SortOfArray.from` (with a mapping) is finally less confusing than >>> a `SortOfArray#map`, for you don't have to look at the doc in order to >>> determine the type of the result... :-p >>> >>> >> Also related, and came on Twitter just not: >> https://twitter.com/DmitrySoshnikov/status/519964146637737986 >> >> The mapping function from `Array.from` considers holes (from the new TC39 >> "policy"), but `Array#map` does not. >> >> I guess this doc on `Array.from` from MDN [1] should be fixed then: >> >> > More clearly, Array.from(obj, mapFn, thisArg) is the same as >> Array.from(obj).map(mapFn, thisArg), except that it does not create an >> intermediate array. >> >> Since not only they are "the same" (as we confuse/substitute pre- and >> post- mapping), but also the mapping function itself behaves differently. >> >> [1] >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from >> >> > Never mind, as Rick and Allen clarified, they will produce the same > arrays, because of behavior of `Array.from` which as a result already has a > hole converted to explicit `undefined` value. Here is an example: > http://gyazo.com/4709305f3bde1c8ce0b02d2071a99e7f > > However, these are two different semantics, although are both pre-mapping: ``` Array.from([1,,2].map(x=>x*x)); // [1, 4] Array.from([1,,2],x=>x*x); // [1, NaN, 4] ``` Dmitry
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss