RE: Guidance on using sequences and arrays

From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]

> On 6/26/13 11:00 AM, Marcos Caceres wrote:
> >> As in get notified when it changes? Or as in always see whatever the
> >> state is now as opposed to what it was then?
> >
> > Yes, get notified when it changes.
> OK, that tells you nothing about array vs sequence.  As in, when the notification happens you could re-examine the object you already have, or you could getCalls() to get a new sequence, depending on whether the object you have mutates itself.

This is actually a really important point. `getCalls()` returning a fresh, but mutable, array seems much more reasonable than a `calls` property that (a) cannot be messed with by script; (b) changes out from under you due to C++ magic. Unfortunately that does kill any hopes of using `Object.observe` since there's no single object you can observe.

I think if you contemplated how to implement this in JavaScript there's not much else that would make sense. (Could be wrong, though!)

(On second thought, I suppose a two-layered system like promises have, where the creator retains modification rights but the user cannot mess with it, would work. But that would definitely not be array-like in behavior, and would need to be implemented using proxies, so, kinda weird.)

Received on Wednesday, 26 June 2013 15:23:51 UTC