Deleting Getters and Setters (was Re: Controlling DontEnum...)

Brendan Eich brendan at
Mon Mar 17 15:14:29 PDT 2008

On Mar 17, 2008, at 3:08 PM, Mike Shaver wrote:

> On Mon, Mar 17, 2008 at 5:36 PM, Brendan Eich <brendan at>  
> wrote:
>>  For backward compatibility with SpiderMonkey, one might like 2' to
>>  make a getter that can be deleted.
> That pattern is used in Firefox now (and perhaps elsewhere) to do lazy
> initialization of expensive objects:
> this.__defineGetter__("Debug", function() {
>   var d = loadModule("debug.js");
>   delete this.Debug;
>   this.Debug = d;
>   return d;
> });
> We could adapt, obviously, dunno if it's widely used on the web.

With only SpiderMonkey supporting __defineGetter__, it's not widely  
used. The canonical JS memoization pattern, presented nicely here:

changes (shadows or replaces) a function-valued property, requiring  
callers to add pesky () to invoke the property explicitly. With  
getters and setters, this noise-problem can be avoided and (beyond  
noise reduction) old client code that wanted to get a property, not  
call a method, can be made to call a memoizing wrapper without  
requiring vast or infeasible (you don't own write access to the  
client code) search and replace work.

So getters and setters plus memoization patterns do summon  
__defineGetter__, in our experience.


More information about the Es4-discuss mailing list