> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Brendan Eich > Sent: 28. februar 2008 03:47 > To: Steven Mascaro > Cc: es4-discuss@mozilla.org > 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 positional > > and named parameters, but that's no big deal. Will default values work > > 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}) 1,2 >> h() 10,20 >> h({x:1}) 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. --lars _______________________________________________ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss