ES3 Specification oddness.
Brendan Eich
brendan at mozilla.org
Mon May 19 01:53:39 PDT 2008
On May 19, 2008, at 12:56 AM, Steven Mascaro wrote:
> The use of Date makes things look odd, but I assume the spec means
> something like the following:*
>
> js> function f(){}
> js> f.prototype = {const prop1: 1, prop2: 2}
> js> o = new f
> js> o.prop1 = 42
> 42
> js> o.prop1
> 1
>
> which is the behaviour I'd expect.
>
> * I can't find the notation for const's in object literals.
You're using the ES4 syntax; there's no const in ES3.
Yeah, I picked Date but any standard constructor will do (because
standard constructors have DontDelete + ReadOnly attributes for
their .prototype properties). So you could s/Date/Object/g, but Date
suffices and its toString is less anonymous (i.e., not "[object
Object]").
Other suitable DontDelete + ReadOnly properties than the standard
constructors' prototype properties in ES3 include String length,
Number.MAX_VALUE, etc.
Recollecting more from ES1 days, we did not think about const per se,
but we did want to prevent ReadOnly properties from being overridden
in delegates where related properties and methods that depended on
the ReadOnly value were not overridden, therefore found in a
prototype. Integrity again.
/be
More information about the Es4-discuss
mailing list