ES4 draft: Object

Yuh-Ruey Chen maian330 at
Fri Mar 7 18:30:48 PST 2008

Brendan Eich wrote:
> Suppose we had a predefined, open namespace, say dontenum  (surely  
> not the best name). If you write
> obj = {dontenum::cant_see_me: 33}
> then
> for (i in obj) print(i)
> shows nothing. But
> obj.cant_see_me
> works, because dontenum is always open. No more need for an  
> orthogonal DontEnum attribute.
> Instead of
> obj.propertyIsEnumerable('i_want_to_hide', false)
> users would just say
> obj.dontenum::i_want_to_hide = ...

Interesting and clever proposal. Some thoughts:

- It would become harder to change the enumerability of a property 
(compared to a enumerability method): |obj.prop=obj.dontenum::prop; 
delete obj.dontenum::prop;| That said, I'm not sure there are many use 
cases that involving changing enumerability after the prop's 
enumerability is initially defined.

- If you add setPropertyIsEnumerable(), how would that interact with 
this? Would it change the namespace as described above, or just toggle 
the hidden DontEnum attribute?

- Users may think this dontenum namespace is magical and yet another 
thing to keep in mind, when it really just relies on the namespace trick 
you mentioned. With the introduction of classes and namespaces, the 
rules of enumerability are already more complex, so this adds to the 
cognitive load slightly. BTW, if setPropertyIsEnumerable() is added, 
would it be possible to make fixtures enumerable? Enumerability is 
orthogonal to static analysis (which fixtures are meant to help with), 
so I don't see why not.

- The name sucks :p

> > Object.prototype.iterator::setPropertyIsEnumerable(prop,
> > enable). For consistency, you could also have
> > Object.prototype.iterator::isPropertyEnumerable(prop) which  
> > delegates to
> > Object.prototype.isPropertyEnumerable(prop).
> Clever relocation of "is" in the predicate names ;-). We're probably  
> stuck with propertyIsEnumerable.

Honestly, that wasn't intentional - it just came off my fingers naturally :)

-Yuh-Ruey Chen

More information about the Es4-discuss mailing list