ES4 draft: Object initializers

Lars Hansen lhansen at
Tue Apr 8 12:20:37 PDT 2008

> -----Original Message-----
> From: es4-discuss-bounces at 
> [mailto:es4-discuss-bounces at] On Behalf Of Lars Hansen
> Sent: 7. april 2008 16:20
> To: es4-discuss at
> Subject: RE: ES4 draft: Object initializers
> Here is the second draft, which incorporates most things 
> discussed so far.  Changelog near the beginning, with an OPEN 
> ISSUES section.

One facility that was introduced in this draft copies the
type tags of 'const' and 'var' attributed properties into
the type of the object, for "ease of use".  As a consequence,
this test is true:

  { const x: "foo" } is { x: string }

I am going to remove that facility again because it violates
the "explicit is better than implicit" principle.  IMO the
programmer should state her intent:

  { const x: "foo" } : { x: string }

Type definitions help make this somewhat less wordy.  And with
or without the type annotation x would still be a read-only
fixture, as desired, but the type of the x property would
be "*", not "string".

(It's easy to say that when the literals are simple then the
types are obvious, but once they involve more complicated
expressions I'm guessing the gains are illusory.)


More information about the Es4-discuss mailing list