Controlling DontEnum (was: ES4 draft: Object)

Brendan Eich brendan at mozilla.org
Tue Mar 11 12:45:08 PDT 2008


Here is a modest proposal based on Mark's and Maciej's messages:

Goal: A detectable method requiring no new syntax to set the DontEnum  
attribute on an existing property.

Goal: Avoid breaking any existing ES3 code that might depend on a  
plainly named method not being predefined.

Anti-goal: The ability to turn off DontEnum where it has been set on  
predefined properties.

Proposal: Add Object.prototype.__makePropertyNonEnumerable__(name),  
defined as if by:

     Object.prototype.__makePropertyNonEnumerable__ = function (name) {
         if (this has a direct property identified by name) {
             set the DontEnum attribute for this[name];
             return true;
         }
         return false;
     }

Note that if this has a direct property identified by name, but this 
[name] already has the DontEnum attribute, then the function returns  
true. The specification with prose of setting DontEnum would occur  
redundantly in this case, but it is not observable in ES3 or ES4 as  
proposed, so for simplicity I left out a test of DontEnum to avoid a  
redundant set.

The use of a __-bracketed name satisfies the second goal, but it  
would be a problem for Caja or similar. This is an issue where I  
would appreciate Mark's feedback.

Comments welcome.

/be



More information about the Es4-discuss mailing list