foo(...args) [Was: super.apply(this, arguments)]

Lars Hansen lhansen at adobe.com
Thu Mar 6 10:53:02 PST 2008


There's an open ticket on it that proposes just that, neither accepted
or rejected, really.  The super(...args) seems like an important use
case.

http://bugs.ecmascript.org/ticket/357

--lars 

> -----Original Message-----
> From: es4-discuss-bounces at mozilla.org 
> [mailto:es4-discuss-bounces at mozilla.org] On Behalf Of P T Withington
> Sent: 6. mars 2008 10:48
> To: Brendan Eich
> Cc: es4-discuss Discuss; Dean Edwards; Jeff Dyer; Lars T Hansen
> Subject: foo(...args) [Was: super.apply(this, arguments)]
> 
> Did the use of ... in the parameter list (in the tail position only, I
> assume) of a function call to 'spread' an array of arguments 
> get accepted into the language?  Is the proper way to 
> trampoline all my constructor args to my superclass going to be:
> 
> class Foo extends Bar {
>    function Foo(...rest) : super(...rest) {
>      ...
>    }
>    ...
> 
> ?
> 
> On 2007-12-21, at 00:39 EST, Brendan Eich wrote:
> 
> > On Dec 20, 2007, at 4:01 PM, Jeff Dyer wrote:
> >
> >> The original Netscape ES4 proposal had syntax for passing 
> arguments 
> >> as an array. (Waldemar are you listening?) IIRC it used 
> triple dots 
> >> like
> >> this:
> >>
> >>   foo(...args)
> >>
> >> to mean use the elements of 'args' as positional arguments 
> of foo. We 
> >> dropped this from AS3 for lack of evidence for its need.
> >
> > Wow. I like this, never saw it in Waldemar's proposals, but 
> of course 
> > Python and other languages have something akin. This is the missing 
> > solution that satisfies the demand for compositional new 
> and apply, as 
> > well as other apply-like use-cases (see the thread on this 
> very list, 
> > inspired by Python, starting here).
> >
> > Presumably you could supply one or more positional actual 
> parameters 
> > before the "packed" parameter, as Python allows:
> >
> > >>> def foo(a,b,c):
> > ...   print a,b,c
> > ...
> > >>> foo(1,2,3)
> > 1 2 3
> > >>> a = [1,2,3]
> > >>> foo(*a)
> > 1 2 3
> > >>> b = [2,3]
> > >>> foo(1,*b)
> > 1 2 3
> >
> > This beats a super.apply special form any day!
> 
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
> 



More information about the Es4-discuss mailing list