[Harmony proxies] Thoughts on the almost-dead "receiver" argument

David Bruant david.bruant at labri.fr
Mon Sep 26 06:15:47 PDT 2011

Le 26/09/2011 14:35, Tom Van Cutsem a écrit :
> 2011/9/24 David Bruant <david.bruant at labri.fr 
> <mailto:david.bruant at labri.fr>>
>     Yet, I still think that not having at the object-level the
>     equivalent of
>     what we can do at property-level (with getter/setters changing things
>     based on the receiver object) would be a miss.
> Would it really? Javascript data properties are currently simple and 
> easy to understand. In pure JS, it's not possible to have a data 
> property's value depend on the receiver. If you need such a thing, you 
> resort to accessors. The good thing about this is that the "magical" 
> behavior of the property shows up via the Reflection API 
> (getOwnPropertyDescriptor will return an accessor property 
> descriptor), warning the client about the property's behavior.
> If proxies would allow data properties to depend on the receiver, that 
> may lead library and/or spec writers away from using accessors, which 
> is not necessarily beneficial. I realize it's a fairly weak argument, 
> since proxies make the behavior of all (configurable) properties 
> magical. Still, proxies currently can't easily emulate 
> receiver-dependent data properties.
> Of course, changing the inheritance-related traps to accept an 
> additional receiver argument is not a big deal, so if there are good 
> use cases, why not. So far though, I don't see what is wrong with 
> WebIDL using accessors. It seems accessors are the right tool for the 
> job in this case.
> The problematic case would be one where WebIDL would require 
> receiver-dependent data properties.
My point was more general than WebIDL, but i agree.

I've been thinking about it more, trying to find examples, relavant use 
cases (and trying to keep my bad faith as low as possible :-p).
I have not found one, but I have come to the conclusion that there is a 
fundamental difference between a per-instance behavior at property and 
object level: if you want a per instance object-level behavior, well, 
just inherit from another object!

There is no equivalent for properties. When several objects inherit from 
the same object and wish one inherited property acted differently, 
getter/setters are necessary. If several objects inherit from the same 
and wish the prototype object acted differently, it could as well be a 
different object! There is a loss of object identity equality, it 
doesn't make much sense when the behavior is different per instance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110926/1b9a57d5/attachment-0001.html>

More information about the es-discuss mailing list