Re: Array property of custom object
Boris Zbarsky <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
On 5/3/16 3:25 AM, Mihai Dobrescu wrote: > ....well, I did not say js::proxies. OK, let's not use "proxy" without clearly stating which of the many meanings we're using, because that way lies only frustration. > I could ask also, how do you know should be done? For any of these, simple and array properties. If you do it from scratch, what is your approach? Let me try to state this more clearly. If you want |var x = obj.arr| to return an object that will call code you control when x[5] is read or set, and the precise set of property names for which you want your code to be called is not known up front, then obj.arr needs to be a js::Proxy. The proxy handler's methods are what will get called when x[5] is read or set. If you do know the precise set of property names you care about up front (e.g. you want your code to be called for x[N] where 0 <= N < 100, but don't want your code called when N is 101), then you can get away with defining a bunch of accessor properties on obj.arr instead of using a js::Proxy. Obviously for large N this could have deleterious memory effects. Does that help? -Boris