ES4 draft: Object

Maciej Stachowiak mjs at apple.com
Tue Mar 11 04:46:13 PDT 2008


On Mar 11, 2008, at 3:11 AM, Michael Daumling wrote:

> I think that there is general agreement that
>
> 1) Object.prototype should not be polluted
> 2) Namespaces to add functionality are difficult to handle
> 3) Changing a getter to a setter by adding a new parameter is not a  
> good
> idea.
>
> We will have this discussion over and over again as we add properties
> and methods to Object and other classes.
>
> What if we considered a more ES3-like approach?
>
> Let's bite the bullet and add *one* element to Object.prototype. This
> element serves as a container for all future extensions. So, instead  
> of
>
> myObject.propertyIsEnumerable ("myProp", true);
>
> use
>
> myObject.__NameToBeDefined__.setPropertyEnumerable ("myProp", true);
>
> This way, we reserve a "namespace", which in fact is an object, that  
> can
> take all of our current and future extensions without risking to Break
> The Web.

This is not unreasonable, but if adding to Object.prototype is truly  
terrifying then I think the approach Mark Miller linked to, of static  
methods on the Object constructor, is cleaner:

Object.setPropertyEnumerable(myObject, "myProp", true);

It's less object-oriented but free of any pollution of the  
Object.prototype namespace.

It might even be better to make this transition one-way, since it  
shouldn't be allowed to make built-in properties that are DontEnum  
enumerable:

Object.makePropertyNonEnumerable(myObject, "myProp");

Regards,
Maciej




More information about the Es4-discuss mailing list