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

Brendan Eich brendan at mozilla.com
Wed Jun 22 23:34:01 PDT 2011


On Jun 22, 2011, at 3:55 PM, Axel Rauschmayer wrote:

>> You should not in general mutate shared prototype state via one of N delegating objects. It leads to trouble.
> 
> What’s the difference to a global variable?

The list is long.

How about this? You have a bunch of local variables in various functions referencing different objects. But by some obscure yet legal means you use one such reference to mutate the prototype object they share in common, so all the others appear to be mutated too.

This is not inherently "evil", but it's usually a bug. Usually the other different objects do not wish to be mutated so indirectly, and the users of their properties (own and delegated) in those various functions may not be prepared for such a change.

Consider monkey-patching. You want to add value to a shared prototype, but you might break for-in loops. Ok, that can be solved with ES5 Object.defineProperty -- but not if the mutation breaks some other invariant.

It's occasionally useful to do AOP on shared prototypes. My point is that you ought to address them directly by their true names (Array.prototype, e.g.; not Object.getPrototypeOf(someArray)).

/be



More information about the es-discuss mailing list