mathiasbynens / Array.from

A robust & optimized ES3-compatible polyfill for the `Array.from` method in ECMAScript 6.
https://mths.be/array-from
MIT License
67 stars 15 forks source link

ES6 draft rev23 updates #5

Closed mathiasbynens closed 10 years ago

mathiasbynens commented 10 years ago
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.

mathiasbynens commented 10 years ago

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.
mathiasbynens commented 10 years ago

https://github.com/mathiasbynens/Array.from/blob/1e9b05dd983c575ebe12255fea522cd76113e090/array-from.js#L59 Looks like the last parameter items should be removed as per the latest http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from.

ljharb commented 10 years ago

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