An update on Object.observe

Isiah Meadows isiahmeadows at
Wed Nov 4 06:28:11 UTC 2015

Reflect.construct basically does `new Class(...args)`, but on a lower level
where you can set `` in the call.

Object.observe makes it easier, but sometimes, it's useful to completely
break encapsulation from a closure. I've had a few use cases where I needed
that ability. There's been a couple times where I've explicitly yanked a
value out of a callback closure just to use it elsewhere.

And generally, Object.observe is useful for one of two things: listen for
changes as a break for encapsulation, which is what Angular 1 wanted it
for, or transfer changes to a new closure, which leads to extremely simple
POJO models in MV* architectures.

I did find a way to use it in Flux architectures as well. Here's a copy of
an email I already sent:


I was just thinking... Object.observe could, in theory, be used as a core
for a dispatcher and store in a Flux-like data flow. Basically, when a view
emits an event, you can use the first observed object as a memoized
dispatcher, and then it emits a list of changes that can then update
another observed object, the store. That store can then emit a list of
changes to be resolved with the views.

What do you all think?

On Wed, Nov 4, 2015, 01:17 Coroutines <coroutines at> wrote:

> On Tue, Nov 3, 2015 at 10:08 PM, Isiah Meadows <isiahmeadows at>
> wrote:
> > Proxies can do a better, more thorough job of breaking encapsulation.
> >
> > ```js
> > var log = [];
> > String = new Proxy(String, {
> >   construct(target, newTarget, args) {
> >     log.push(args);
> >     return Reflect.construct(target, newTarget, args);
> >   }
> > });
> >
> > (function () {
> >   var s = String;
> >   var private = function () { return new s("cat"); }
> >   var public = function () { return private(); }
> >   return public;
> > })()
> > ```
> There's a possibility I am misunderstanding you but this is what I was
> trying to say is 'okay'.  If you redefined String to be a proxy before
> the closure runs then that seems "legal".
> I disagree with Object.observe() because you can call it after the
> closure has run and see changes made in String (or another object for
> lack of a better example) when you call the exported function.  ...but
> now I need to go read up on Reflect.  Be back in a few mins when I
> have more slightly inaccurate things to say :o)
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list