mathiasbynens / Array.from

A robust & optimized ES3-compatible polyfill for the `Array.from` method in ECMAScript 6.

Home Page:https://mths.be/array-from

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ES6 draft rev23 updates

mathiasbynens opened this issue · comments

Array.from({ '0': 1, '2': 2, 'length': 3 }) should not return a sparse array

Discussed in http://esdiscuss.org/topic/array-from-and-sparse-arrays.

Array.from([1,,2]) returns a non-sparse array (because it uses the iterator case, see bug 2416), but Array.from({0: 1, 2: 2, length: 3 }) returns a sparse array (because it uses the ‘array-like’ case).

It was suggested that the two cases should be made consistent. Since “holes
are evil”, the array-like case should lose the kPresent test in step 17b etc.

IsIterable is not defined

It will be defined in the rev23. Once that happens, #4 can be fixed.

http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts#april_5_2014_draft_rev_23

7.4.2 IsIterable ( obj )

The abstract operation IsIterable with argument obj performs the following steps:

  1. If Type(obj) is not Object, then return undefined.
  2. Let iteratorGetter be Get(obj, @@Iterator).
  3. Return iteratorGetter.

mappedValue = mapping ? mapFn.call(T, kValue, k, items) : kValue;
Looks like the last parameter items should be removed as per the latest http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from.

This appears to have been cleared up - Array.from never leaves a hole. https://twitter.com/awbjs/status/496443722133798912