Analog to Object.getPropertyDescriptor() for *changing* a property value?

Axel Rauschmayer axel at rauschma.de
Tue Jun 21 13:50:27 PDT 2011


That sounds like the opposite argument you are making with regard to the hypothetical |here|:

> BTW I do not agree we can or should try to reserve 'here' or expose the method's "home object" -- that breaks abstractions built using prototypes. 'super' does not, because it always goes to the [[Prototype]] of the object in which the method was defined.

The prototype seems to be the best location for shared data (such as the number of instances of a class). Wouldn’t you also want to abstract from the exact location of such a property?

I find that Common Lisp does this well, via "places":
- Property lookup => returns a place, e.g. a pair (object, property name)
- Use the place to either read the property value or to change it.

Can’t comment on Proxies, though.

On Jun 21, 2011, at 21:36 , Brendan Eich wrote:

> On Jun 21, 2011, at 8:24 AM, Axel Rauschmayer wrote:
> 
>> As a loose analog to the prototype-chain-traversing getPropertyDescriptor(), I would still like to have something that allows one to easily *change* properties higher up the prototype chain (e.g. to use a prototype to share state).
> 
> Such mutation from a delegating object, because it affects all other objects that delegate to the shared prototype, is usually a bug! Shared mutables are a bitch, even ignoring threads.
> 
> I think it would be better to require the mutation to have a direct reference to the prototype. Yes, it could be discovered via Object.getPrototypeOf -- assuming no proxies.
> 
> We cannot assume no proxies, and a Proxy is responsible for delegating to possibly hidden objects other than the |proto| passed to Proxy.create.
> 
> Even without proxies, or assuming they behave like native objects, mutation from one of N delegating objects is an anti-pattern.
> 
> /be
> 
> 
>> 
>> Maybe it would be enough to just have Object.getDefiningObject(obj, propName):
>> http://www.mail-archive.com/es-discuss@mozilla.org/msg06652.html
>> 
>> But I can also imagine syntactic sugar:
>>       obj.foo := "abc"
>> desugars to
>>       Object.getDefiningObject(obj, "foo").foo = "abc"
>> 
>> -- 
>> Dr. Axel Rauschmayer
>> 
>> axel at rauschma.de
>> twitter.com/rauschma
>> 
>> home: rauschma.de
>> blog: 2ality.com
>> 
>> 
>> 
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> 
> 

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com





More information about the es-discuss mailing list