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

Coroutines coroutines at gmail.com
Tue Nov 3 23:22:33 UTC 2015


On Tue, Nov 3, 2015 at 12:20 AM, Tom Van Cutsem <tomvc.be at gmail.com> wrote:

> What O.o would provide beyond Proxy is the ability to observe changes to
> already pre-existing objects.

I think I missed something important here.

You can watch for events with both Proxy and Object.observe() - but
Object.observe() lets you maintain the same object identity because
you're not replacing references to the watched object.

Let's say I want to watch for events on an object *I create*: I create
a Proxy to that object and then expose references to that proxy (not
the target object).  This is fine and dandy but if I want to observe
events on something like the `String` object/class (and its prototype)
I cannot replace all localized references to it in various modules.
Object.observe() could be seen as a 'cheat' in a sense that you can
observe events happening on the target object from code that is hidden
from you by a closure in another module (as long as you have a
reference to that object from where you use Object.observe()).  With
Proxy you can only observe changes where you can replace the target
object's references.

With Object.observe() you get a global view of events generated by the
target object, with Proxy you need to replace references to the target
object with references to the Proxy.

Now I'm changing my opinion again.  We need both.

But because of what Object.observe() can do to see into closures, I'd
relegate it to privileged code :>  It is incredibly useful for
debugging.


More information about the es-discuss mailing list