Well my use case is for something I can insert into an existing function,
in fact, a lot of functions, hopefully without manually listing the
arguments.

```js
function bar( parameters ) {
    for ( var i = 0; i < parameters.length; i++ ) {
        // do something interesting with each parameter of the function
    }
}

function foo( a, b = 2 ) {
    bar( parameters );

    // do normal foo stuff
}
```

Thinking about it I can't see how Reflect could do this, because it's
surely meant to be external to the function. For example with an imaginary
Reflect.getParameters:

```js
Reflect.getParameters( foo ) // could only give me [ a: undefined, b: 2 ]
as reflect can't know what foo was called with from outside the function.
```

On 25 March 2015 at 19:12, Axel Rauschmayer <a...@rauschma.de> wrote:

> I'm all for using Reflect, but looking at the API as listed on MDN, the
>>> harmony-reflect github, or the spec, i don't see an obvious way of getting
>>> the parameters.
>>>
>>
>
> If I understand you correctly (and this is not about parsing the parameter
> definitions) then how about the following solution?
>
> ```js
> function foo(…args) {
>     let [a, b = 2] = args;
>     return args;
> }
> ```
>
> Original code:
>
> ```js
> function foo( a, b = 2 ) {
>     return arguments;
> }
> ```
>
> --
> Dr. Axel Rauschmayer
> a...@rauschma.de
> rauschma.de
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to