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

David Bruant david.bruant at
Thu Jun 23 04:19:53 PDT 2011


In a the provided example, you assign a value. Can't you just use a 
getter/setter pair on the prototype chain? It sounds like it would solve 
your use case (without the syntax sugar). On ES5 - 8.12.5 step 4 & 5, 
the prototype chain is climbed to look up for an accessor and if there 
is a setter (anywhere on the prototype chain), this setter is called. 
Combined with the fact that a getter naturally do the same thing for 
getters, you have your way to change a value "directly on the prototype 
Of course, if you want to change the property descriptor on the 
prototype chain, none of what I said apply.


Le 21/06/2011 17:24, Axel Rauschmayer a écrit :
> 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).
> Maybe it would be enough to just have Object.getDefiningObject(obj, propName):
> But I can also imagine syntactic sugar:
> := "abc"
> desugars to
>          Object.getDefiningObject(obj, "foo").foo = "abc"

More information about the es-discuss mailing list