Skip to content
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
bathos opened this issue Mar 9, 2018 · 3 comments
Closed

Should array-like argument be permitted? #9

bathos opened this issue Mar 9, 2018 · 3 comments

Comments

@bathos
Copy link
Collaborator

bathos commented 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)

@ljharb
Copy link
Member

ljharb commented Mar 9, 2018

This is a good question, but I don't think it's actually necessary to accept arraylikes.

@zloirock
Copy link

zloirock commented Mar 9, 2018

See this issue tc39/proposal-setmap-offrom#3

@bathos
Copy link
Collaborator Author

bathos commented Mar 9, 2018

Great link! Closing, seems clear that genuine iterables are all we should accept.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants