This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
Should array-like argument be permitted? #9
Closed
Description
openedon Mar 9, 2018
Currently it’s expected that the argument to Object.fromEntries
be an iterable in the Symbol.iterator
sense.
The Array.from
and %TypedArray%.from
methods permit array-like arguments; they fall back on looking for an appropriate length property and numeric keys. Because the ToLength operation coerces most values to 0, this means that they will also accept most objects:
Array.from({})
// []
Array.from({ length: 1 })
// [ undefined ]
Array.from({ length: Infinity })
// RangeError
My sense (which might be wrong) is that support for array-likes was a way to help bridge the gap with pre-ES2015 APIs. Should a new "from" method also support array-likes, or should it be limited to formal iterables like the Map and Set constructors?
See #8 (comment)
Metadata
Assignees
Labels
No labels
Activity