tc39 / proposal-array-from-async

Draft specification for a proposed Array.fromAsync method in JavaScript.
http://tc39.es/proposal-array-from-async/
BSD 3-Clause "New" or "Revised" License
179 stars 13 forks source link

Inclusion of numeric argument in receiver instance creation? #22

Closed senocular closed 2 years ago

senocular commented 2 years ago

From readme Generic factory method:

fromAsync can be transferred to or inherited by any other constructor with a single numeric parameter. In that case, the final result will be the data structure created by that constructor (with 0 as its argument)...

While species and of() create arrays with a numeric argument, presumably since they'd be able to have knowledge of predetermined length, shouldn't fromAsync() be consistent with from() since the length of the iterable would/could be unknown?

class Custom extends Array {
    constructor (length) {
        super()
        console.log('Argument length:', length)
    }
}
Custom.from([1,2,3]) // Argument length: undefined
js-choi commented 2 years ago

Yes, this is a mistake in the explainer. (The specification as written is currently correct, since it is based on Array.from.) I will fix this later.