Default argument values

Lars Hansen lhansen at
Thu Feb 28 07:29:42 PST 2008

> -----Original Message-----
> From: es4-discuss-bounces at 
> [mailto:es4-discuss-bounces at] On Behalf Of Brendan Eich
> Sent: 28. februar 2008 03:47
> To: Steven Mascaro
> Cc: es4-discuss at
> Subject: Re: Default argument values
> On Feb 27, 2008, at 6:35 PM, Steven Mascaro wrote:
> >> This is not to knock named parameters, just to explain why they 
> >> never made it into a serious proposal in the modern ES4 era.
> >
> > That sounds fine. The only thing it misses is interchanging
> > and named parameters, but that's no big deal. Will default values
> > by doing the following?
> >
> > function foo({option1, crud2, frob} = {option1: 1, crud2: "dirty",
> > frob: "enius"}) { ... }
> That should work.

It's cute, but there's nothing in our language discussions so far that
indicates that it should work to provide defaults where the caller
provided none, and making it work is pretty much tantamount to getting
into a discussion about named parameters or a more general notion of
destructuring where it picks up values where there are none.  (At the
risk of starting another "goto" discussion, imagine an operator "?=".)

In fact the RI doesn't work as one would like it to, as the third test
below shows:

>> function h({x:x, y:y} = { x:10, y:20 }) [x,y]
>> h({x:1,y:2})
>> h()
>> h({x:1})

What appears to happen here is what one would expect: if the entire
structure argument is omitted then the default value is used, but if the
structure is partly omitted then the default structure is not consulted
at all, and I think that's what Steven would like to see happen.


More information about the Es4-discuss mailing list