Re: Array property of custom object
Mihai Dobrescu <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
On Tuesday, May 3, 2016 at 6:49:08 PM UTC+3, Boris Zbarsky wrote: > On 5/3/16 11:28 AM, Mihai Dobrescu wrote: > > Now, I have the question how could I use js::proxy to attain my goal, being aware of its drawbacks. I'm sure it involves memory fragmentation and cpu load. > > I don't see why it would involve "memory fragmentation". > > To use a js::Proxy, you define an appropriate proxy handler to do > whatever you want. Basically, you directly implement the various > internal methods from the ES spec for your object. > > http://mxr.mozilla.org/mozilla-central/source/dom/base/WindowNamedPropertiesHandler.cpp > has an example of a simple proxy that you might be able to repurpose. > > > Will it make possible to simply iterate too? > > I don't know what you mean by "iterate" exactly, but obviously a proxy > would allow you to do for-in enumeration (via > getOwnEnumerablePropertyKeys) and you can always do for-of iteration by > providing an iterator implementation for your object. > > -Boris By iteration I mean to loop through array's elements.