Better property behavior

Allen Wirfs-Brock allen at
Mon Dec 31 12:54:28 PST 2012

On Dec 31, 2012, at 10:14 AM, Axel Rauschmayer wrote:

> Currently making a typo in property names can be fatal in two ways: When reading a property, things fail silently and you get back `undefined`. When setting a property, you accidentally create a new property.
> A safer behavior would be as follows:
> 1. Creating properties
>     1a. Only property definition creates own properties.
>     1b. Assignment throws if a property does not exist, yet.
> 2. Reading from a property that does not exist throws an exception.
> (2) can be done by putting a proxy in the prototype chain that throws if it is reached by the search for a property.
> (1b) can be done by making an instance non-extensible. Plus strict mode.
> Not sure how to achieve (1a). You’d have to make all of your definitions first. But once you have prevented extensions, that would be it.

1a can also be handled by your proxy's put trap.  All it needs to do is refuse to create new properties on the "receiver" object.

> Does that make sense?

For some new language, probably hot for JS.

Perhaps you could find some utility to this technique as a debugging tool.


More information about the es-discuss mailing list