Re: [heycam/webidl] Separate value iterators from indexed getters (#338)

+1. Subclassing arrays would be *ideal* for [CSSUnparsedValue](https://drafts.css-houdini.org/css-typed-om/#unparsedvalue-objects) and [CSSTransformValue](https://drafts.css-houdini.org/css-typed-om/#transformvalue-objects), which are both dead (UA doesn't modify them after creation, user mutation has no special effect) lists, but have additional properties that preclude just making them bare Arrays.  Making them at least iterable is a "good enough" solution; at least then authors can do:

```js
let arr = [...cssomThing];
mutateArr(arr);
let newCssomThing = new CSSUnparsedValue(arr);
```

Less good than just `mutateArr(cssomThing)`, but hey, *it works*.

> Still, as before, requires defining what the actual behavior of things like forEach and the actual iteration should be. Coupling to indexed getters allowed us to free-ride on the Array bits from ES.

You just... define them the same way. (Specifically: forEach's callback arguments are (element, index, collection) like Array.forEach, not (element, element, collection) like Set.forEach; iteration is "live" and run by just iterating an index over the collection, so mutation in the loop interacts with iteration, rather than making a copy and iterating over that.)

Context: in <https://github.com/heycam/webidl/issues/291#issuecomment-284897010> Boris said one of the original problems with value iterators was disagreement on whether they should iterate like Sets or Arrays. Since people seemed to be okay with "uh, just free-ride on Arrays" as an answer, I'm not sure what the problem is - you make them act like an Array.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/338#issuecomment-291898021

Received on Wednesday, 5 April 2017 15:28:28 UTC