Save Object.observe()! (please) + make WeakMap/WeakSet observable.

Tom Van Cutsem at
Tue Nov 3 08:20:13 UTC 2015

2015-11-02 23:34 GMT+01:00 Coroutines <coroutines at>:
> I come from Lua.  In Lua we make proxy objects with metamethods.  You
> create an empty table/object and define a metatable with a __index and
> __newindex to catch accesses and changes when a key/property doesn't
> exist.  I would primarily use this in sandboxes where I wanted to
> track the exact series of operations a user was performing to modify
> their environment (the one I'd stuck them in).

For this type of use case, you can use an ES6 Proxy <>.
You can think of the proxy handler's methods as the 'metamethods' of the
proxy object.

What O.o would provide beyond Proxy is the ability to observe changes to
already pre-existing objects. However, since you mention you'd start with
an empty table/object, you should be able to create a fresh Proxy and use
that to trace all property accesses.

Proxies are particularly well-suited when you want to sandbox things, since
you should be in control of the sandboxed environment anyway and can set-up
proxies to intermediate. O.o is particularly well-suited to scenarios where
there are already plenty of pre-existing objects and you don't know ahead
of time which ones to observe and which not.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list