-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iterable's should have more than just forEach() #561
Comments
It's more than
But yeah, it's worth investigating if we can add more. |
This has come up a few times. Realistically, this is why I supported |
Even nicer would be if ES had facilities for doing this stuff by default on anything that has keys/values/@@iterator, because then it would Just Work. But the current facility for it is |
Or |
That one is pretty inefficient, though. |
The main reason we removed So therefore our options seem to be:
|
For 1, it's definitely already a pattern (with |
IMO if you want an array, you should not be using |
@domenic it's not clearly stated in OP, but the goal of this discussion is to improve |
@annevk thanks for clarifying the intent. I agree with @domenic that an What is clear is that developers want an array-like - so maybe @bzbarsky's whack-a-mole solution (#561 (comment)) could work with maybe a |
As per #561 (comment) we'll have to test those properties individually as we know adding all of them breaks the web. |
Sure, agree. Is there precedent for how we go about testing this web compat? |
Was the we breakage from properties, or from instanceof Array? |
I don't remember. |
Maybe something about |
I looked it up: the specific compat issue was people doing .concat() on nodelists because they tested true for instanceof Array. So nodelists that were ArrayClass and implemented @@isConcatSpreadable would not have had the one known compat issue. The real issue was that no one except Gecko was interested in implementing [ArrayClass]... |
Or when you want something that looks like an Array but actually implements the same sort of typechecking that every single other object in WebIDL is allowed to implement... |
I hope the ES array methods (edit: optionally) use |
Which methods? Generally speaking, the Array generics in ES in fact use the |
Nearly all, except Array.prototype.find.call(iterableWithoutLength, fn); // does not creates a new array |
https://tc39.github.io/ecma262/#sec-array.prototype.find gets the |
iterable declarations adds
.forEach()
method to an interface, which is nice... however, only having forEach is too limited - would be great if iterable declarations got all the useful Array methods, like.reduce()
,.find()
, etc.The text was updated successfully, but these errors were encountered: