ES4 draft: Map

Lars Hansen lhansen at adobe.com
Tue Mar 11 11:06:06 PDT 2008


> -----Original Message-----
> From: Erik Arvidsson [mailto:erik.arvidsson at gmail.com] 
> Sent: 11. mars 2008 11:25
> To: Lars Hansen
> Cc: es4-discuss at mozilla.org
> Subject: Re: ES4 draft: Map
> 
> I still find this bad UI for people that do not use types, 
> and remember types are supposed to be optional.  

I agree, default type parameters would be nice.

> Currently 
> there is no way to create a map without providing types (not 
> entirely true, see below).  Neither of the following works as 
> we have speced it today:
> 
> var m = new Map;
> var m2 = Map();

The latter should work, thanks for catching the bug.

> the closest thing would be to do
> 
> var m3 = Map({});
> 
> but that is pretty ugly.

And very likely it will become illegal, since we think that class
statics will only be available on instantiated classes (unlike now,
when they are available only on uninstantiated classes), so you'd
have to write

  var m3 = Map.<string,int>()

or worse.

> What I would like is that the type params are optional and if 
> left out treated as the any type.  Another simpler option is 
> to make the argument to meta::invoke to be optional and if 
> left out an empty Map.<EnumerableId, *> is returned.

We discussed default type parameters a few times, but it was always
thrown out.  I think the chief reason for that was that we always
tried to make it work in the context of Array (so that Array could be
both what it is in ES3 and something typed besides).  That was a
non-starter, and rightly so.

In any case, this was the sketch we were toying with:

  class Map.<K=EnumerableId, V=*> {
  }

One issue that I remember was the question of the meaning of
an expression that names the type without parameters.  For example,
if we want

  new Map() 

to mean 

  new Map.<EnumerableId,*>()

(and this is what you're asking for) then what do we mean when we say
simply 

  Map

?  Do we mean to pass the uninstantiated class object around or do we
mean to instantiate it with the default parameters?  The former is the
obvious interpretation, but then what about

  x = Map
  new x()

Does that instantiate, and so on?  No doubt all these details could be
resolved, we just thought that some things should be postponed to ES5.

--lars

> 
> 2008/3/11 Lars Hansen <lhansen at adobe.com>:
> > Draft 3 enclosed.  Changelog near the top; the only significant  
> > change is fixing the bug Erik noted in the prototype get  and put 
> > methods.
> >
> >  Please note one open issue; the current design is probably 
> OK but  I 
> > would appreciate comments.
> >
> >  --lars
> >
> >
> >
> >  > -----Original Message-----
> >  > From: Lars Hansen
> >
> >
> > > Sent: 3. mars 2008 02:03
> >  > To: Lars Hansen; es4-discuss at mozilla.org  > Subject: RE: 
> ES4 draft: 
> > Map  >  > Draft 2 enclosed (changelog near the top).
> >  >
> >  > --lars
> >  >
> >  > > -----Original Message-----
> >  > > From: es4-discuss-bounces at mozilla.org  > > 
> > [mailto:es4-discuss-bounces at mozilla.org] On Behalf Of Lars 
> Hansen  > > 
> > Sent: 29. februar 2008 11:34  > > To: es4-discuss at mozilla.org  > > 
> > Subject: ES4 draft: Map  > >  > > I'm enclosing the draft 
> for the Map 
> > class.  Please comment.
> >  > >
> >  > > --lars
> >  > >
> >
> > _______________________________________________
> >  Es4-discuss mailing list
> >  Es4-discuss at mozilla.org
> >  https://mail.mozilla.org/listinfo/es4-discuss
> >
> >
> 
> 
> 
> --
> erik
> 



More information about the Es4-discuss mailing list