Skip to content
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

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions