Proxy's optional target

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Tue Jan 15 10:08:47 PST 2013


On Jan 15, 2013, at 12:54 AM, David Bruant wrote:

> Le 15/01/2013 06:53, Dmitry Soshnikov a écrit :
>> 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.
> Just to clarify a point. It is not entirely useless. It's used for invariant checks and as storage back-end, obviously.
> 

Sure, and it (the target) still would be there, just created implicitly. All the invariants are kept, the storage (the implicit target) is kept.

But, that's mentioned, if the target is implicit, then handler functions look a bit weird when receive it as the first argument.

Dmitry



More information about the es-discuss mailing list