[Bug 22391] Sequence or Array

https://www.w3.org/Bugs/Public/show_bug.cgi?id=22391

--- Comment #10 from Domenic Denicola <domenic@domenicdenicola.com> ---
(In reply to comment #9)
> Domenic, I'm not sure what you mean by "non-frozen, snapshot".

"Non-frozen" = normal writable JS array; "snapshot" = does not track the
underlying mutable state, but instead gives you the elements that were
available when you called the method. Basically I was talking about exactly
your case 1.

> 2)  API that keeps returning the same array object as long as its contents do not change.  This can be a method, of course (returning a frozen JS Array, say, so that one caller can't mess up what other callers see).  Can it be a property getter?  It seems like this is an OK thing to do, actually, since the new object would only appear when the list being represented has in fact changed.

I think you're right; property getters are OK, at least if the returned array
is frozen. It would be quite easy to implement such a property in JS using a
getter that regenerates and caches an array if it detects a change in the
underlying data. Put another way, this might be a natural pattern for ES5
developers who want to expose read-only views of mutable data to the outside
world.

A method feels a bit more preferable, but probably just because I'm used to
working with so much ES3 code. Specific use cases might be helpful in deciding
whether we want to recommend methods or properties.

> 3)  APIs that return some sort of live arraylike collection.  The problem here is that in most cases the liveness means that the DOM implementation needs to be able to write into the array but callers need to not be able to do so.  What that means is that the script-visible behavior is basically some sort of proxy around an Array.

After a brief chat with darobin in IRC, I am no longer convinced this is a bad
pattern, if done correctly. The difference between an array that does this (via
proxies) and an object that does this (via getters) seems insubstantial.

But, the correct way to do this needs some noodling before we even consider
recommending it; the current patterns in the platform are scary. I'll try to
make some time to draw up a readonly-array direct proxy that feels intuitive
enough that we could consider using it. It might not be possible.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Received on Wednesday, 10 July 2013 20:52:08 UTC