Assigning to ReadOnly properties
jwatt at jwatt.org
Mon Nov 12 09:34:56 PST 2007
Brendan Eich wrote:
> On Nov 12, 2007, at 9:00 AM, Jonathan Watt wrote:
>> As I understand it the reason assignment to ReadOnly properties
>> fails silently
>> is that there was no try-catch prior to ECMAScript 3.
> Right. Netscape 2 reported a fatal error, but during ES1
> standardization we agreed to go with silence is (golden|deadly).
>> Could/will edition 4 require an exception to be thrown in strict mode?
> Overtly incompatible, also highly desirable. So opt-in versioning
> could enable this, but it's one more migration headache (see recent
> exchange between Mark Miller and myself). An alternative would be a
> pragma of some sort:
I like the idea of a pragma more than opt-in versioning since it can be used
in-place, and (I guess) placed before and after a section of code to turn the
handling on then off again.
> use readonly error
> or perhaps
> use readonly throw
> We try to make pragmas more readable, sometimes with an extra word;
> not sure this is the best way to phrase it still, but the idea would
> be to enable throwing of a ReadOnlyError on assignment to a ReadOnly
> property. Comments?
Why not just:
It's short, intuitive, and you don't need to remember whether it's "error" or
"throw" in the pragma. If you can use pragmas multiple times to toggle things on
and then off again, perhaps make it:
use ReadOnlyError on
// some code that should throw on assignment to ReadOnly properties
use ReadOnlyError off
Ultimately, the ability to catch this class of error is more important to me
than the syntax to turn the feature on.
More information about the Es4-discuss