Assigning to ReadOnly properties

Jonathan Watt jwatt at
Mon Nov 12 14:22:33 PST 2007

Brendan Eich wrote:
> On Nov 12, 2007, at 9:34 AM, Jonathan Watt wrote:
>> 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.
> Pragmas are block-scoped, so just one should do.


>>>    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:
>>   use ReadOnlyError
> Sure -- pragma convention so far  has been terse and lower-case, e.g.  
> 'use strict' or 'use decimal ...'.

I'm not sure what maintaining case convention gives you here. Using |use
ReadOnlyError| is about as intuitive and easy to remember as it could be I think.

> Speaking of catching, it would be unfortunate if you wrote
>    try { something that might set a ReadOnly property }
>    catch (e : ReadOnlyError) { ... }
> but forgot the pragma, and never heard a word of warning. There are  
> no warnings in the spec, so normative error seems best. But if you're  
> bothering to catch ReadOnlyError, must you also 'use ReadOnlyError'  
> first (in the try, or in a block enclosing the whole try-catch)?

Implicitly enabling ReadOnlyError seems like a very good idea to me (assuming it
can be implemented efficiently). Of course implementations that have facilities
to warn should still warn. Maybe the spec can have non-normative text saying as

Alternatively, maybe it should simply be an error to use ReadOnlyError if it
hasn't been turned on.


More information about the Es4-discuss mailing list