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

Coroutines coroutines at
Wed Nov 4 04:09:58 UTC 2015

On Tue, Nov 3, 2015 at 7:33 PM, Isiah Meadows <isiahmeadows at> wrote:
> There's a reason Object.observe is async: it prevents you from changing how
> the value is first assigned, so it can't work like a proxy. And question:
> how does it let you see hidden closures?

In JS it is common to wrap everything in a (function (){})() for
organization and/or encapsulation purposes.  I would wrap a 'module'
in that, and within that module I might define local references to
common classes/libraries like: var string = require('String');

You cannot reach and redefine that private reference to String within
that module, but you do still have a reference to String from /where
you are/.  If you Object.observe(String) from another place you can
see events generated by the closed-over, private functions of that

In my opinion this is bad, as it breaks the expectation of privacy you
have with a closure.

I think both should stay, but Object.observe() should not be
accessible "from the web" and only used for debugging.  With Proxy you
can't watch events from existing references that are hidden behind
closures.  Proxy creates a separate, 2nd object so it does not have
the same identity.  If you want to make sure you catch all events on
the target object you have to replace all the references to the target
with the proxy.  This is good, and does not allow closures to leak
events from hidden references to the same target you're watching
outside the closure.

More information about the es-discuss mailing list