On Jan 14, 2013, at 9:32 PM, Dmitry Soshnikov wrote:

> Hello,
> 
> Don't know whether it was mentioned/asked before (sorry if so), but just a 
> note: probably it makes more sense making the target argument as optional and 
> the second one in the Proxy constructor's API.
> 
> Proxy(handler[, target]):
> 
> 1. If target is undefined, let the target be new Object();
> ...
> 
> In this case we'll cover (probably the most used) use-case of direct-proxies:
> 
> var p = new Proxy({
>  get: function(target, name, value) {
>    ...
>  }
> });


Although... Actually, never-mind, I just looked at it again, and it looks a bit 
weird having some first argument "target" w/o actually specifying the one at 
creation. So yeah, explicit target makes sense. I just wanted to exclude these 
use-cases:

var p = new Proxy({}, handler);

where this use-less empty "{}" will be to many in proxies' code.

P.S.: I know it's not gonna happen, but in an "imaginary" world:

Anyways, if the explicit target, then it would be good refer it as `this` value 
instead of explicit parameter. But in this case we cannot get reference to the 
handler object (currently `this` refers to the handler object). But. Since 
proxies provide some internal meta-level API handling, we can refer the 
handler's method as private symbols instead. E.g.:

var p = new Proxy({
  @get: function (name, value) {
    if (this.@getOwnPropertyDescriptor(...)) {
      this[name] = value;
    }
  }
});

`this` refers to the target, but this.@getOwnPropertyDescriptor(...) to the 
function of the handler object. But this is only at implementation level, from 
the end-level user's perspective, it looks like `this` is the target and 
`this.@getOwnPropertyDescriptor(...)` is the internal method hook on exactly 
the same target.

In this case, optional target becomes completely implicit and can be treated as 
just a "traceable" object.

This doesn't reflect some invariants as `p === this`, if p is the proxy and 
`this` is the target (and this is why p.name = 10; triggers the handler and 
this.name = 10; inside the handler function does not), so, just thinking saying.

Dmitry
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to