Proxy's optional target

David Bruant bruant.d at gmail.com
Tue Jan 15 00:54:12 PST 2013


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.

David


More information about the es-discuss mailing list