accessing/modifiying getter and setter functions

Brendan Eich brendan at
Wed Apr 4 17:14:13 PDT 2007

On Apr 1, 2007, at 7:15 PM, Kris Zyp wrote:

> According to the spec, it is possible to define getters and setters  
> for the properties. I am wondering if it is possible to access and  
> modify the getter and setter for a property. Can I dynamically set  
> the getter for an object?:
> obj.get x = function() { return 10; }
> Can I access the getter function/method?:
> myGetter = obj.get x;
> Or use the same getter for multiple properties?:
> obj.get y = obj.get x;

The syntax wouldn't look like that (too error-like, prone to  
automatic semi-colon insertion), but something like SpiderMonkey's  
getter= and setter=, which are also available as __define 
{Getter,Setter}__ via Object.prototype could be done. SpiderMonkey as  
__lookup{G,S}etter__ too, as you requested ;-). But these are not  
proposed for ES4, they raise a few questions:

* Under what conditions should it not be possible to replace an  
existing property via __defineGetter__ or __defineSetter__.
* What's the best syntax, given that the old getter/setter= (and o =  
{p getter: function(){...}} etc.) pattern died around the time of ES3?
* Any other gotchas?

At this point we are deferring further work to a post-ES4 edition. I  
expect any proposal along the lines of __{define,lookup}{G,S}etter__  
would be deferred too. It's conceivable that other implementations  
might copy SpiderMonkey's Object.prototype.__... methods in order to  
encourage standardization in the next ECMA edition.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Es4-discuss mailing list