Better property behavior

Axel Rauschmayer axel at
Mon Dec 31 10:14:06 PST 2012

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.

Does that make sense?

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list