- From: Jonas Sicking <jonas@sicking.cc>
- Date: Fri, 15 Nov 2013 18:32:12 -0800
- To: Boris Zbarsky <bzbarsky@mit.edu>
- Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>, Anne van Kesteren <annevk@annevk.nl>
On Fri, Nov 15, 2013 at 6:23 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 11/15/13 9:17 PM, Jonas Sicking wrote:
> The typical way one would use an iterable is something like this:
>
> function f(iterable) {
> for (value of iterable) {
> doStuff(value);
> }
> }
>
> whereas the snapshotting approach is more like:
>
> function f(iterable) {
> var snapshot = Array.from(iterable);
> for (value of snapshot) {
> doStuff(value);
> }
> }
>
> which is slightly odd to do as the default thing with iterables...
These two are only distinguishable from outside of 'f' if doStuff
synchronously calls back into "external code". I agree that for APIs
that does, we need to define if 'f' iterates a snapshot or the
iterator directly.
There are several APIs in ES5/ES6 which does do this. Array.map would
be an obvious example. And for those APIs I believe they explicitly
define that no snapshotting happens.
However in the DOM I think we have very few APIs that synchronously
call back out to external code while using an array-like. The Gecko
implementation of MutationEvents used to do this and that was a royal
pain to implement. It was also a royal pain to use.
In general I think we should try to avoid such callbacks, except in
very explicit APIs like Array.map. However I can't think of any
examples in the DOM.
/ Jonas
Received on Saturday, 16 November 2013 02:33:09 UTC