Proxy forwarding handlers and accessor properties

LungZeno lungzenoopen+es4 at gmail.com
Fri Jun 24 10:08:46 PDT 2011


I suggest to not call it default, use other better name.

On Sun, Jun 19, 2011 at 11:28 PM, David Bruant <david.bruant at labri.fr> wrote:
> Le 19/06/2011 15:53, Tom Van Cutsem a écrit :
>> I agree with all of David's points. I wonder though: would it make
>> more sense if we'd spec. the "get" trap of Proxy.Handler as:
>>
>>   get: function(name, proxy) {
>>     let val = this.target[name];
>>     return typeof val === "function" ? val.bind(this.target) : val;
>>   }
>>
>> Then both method & accessor invocation bind |this| to the target.
>>
>> It's hard to say what the expected default behavior is for the default
>> forwarding handler: should it leave |this| bound to the proxy or to
>> the target when forwarding a method invocation? As David mentioned,
>> programmers can always implement either, but what should be the
>> default? Creating a new bound function per |get| invocation may be
>> expensive though. Also, treating a property bound to a function as a
>> method is an imperfect heuristic.
> And with such a default implementation there would be an object identity
> problem:
> ----
> var target = {};
> target.a =  function(){};
> var f = new ForwardingProxy(target);
>
> f.a !== f.a; // true, because a new bound function is returned each time
> ----
>
> David
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>


More information about the es-discuss mailing list