duktape icon indicating copy to clipboard operation
duktape copied to clipboard

Implement ES2015 extended function argument handling

Open kphillisjr opened this issue 6 years ago • 7 comments

I noticed that there was no bug reports to specifically request adding these Features...

  • [ ] Add Support for Default Parameter Values This is relatively easy, and there is two main ideas on this...
// ES6 - new way
function f (x, y = 7, z = 42) {
    return x + y + z;
}
f(1) === 50;
  • [ ] Add Support for aggregation of remaining arguments into a single parameter.
// es6 - New Method
function f (x, y, ...a) {
     return (x + y) * a.length;
}
f(1, 2, "hello", true, 7) === 9;
  • [ ] Add Support for Spread Operator.
// es6 - New Method
var params = [ "hello", true, 7 ];
var other = [ 1, 2, ...params ];
// [ 1, 2, "hello", true, 7 ]
function f (x, y, ...a) {
   return (x + y) * a.length; }
f(1, 2, ...params) === 9;
var str = "foo";
var chars = [ ...str ]; // [ "f", "o", "o" ]

Note: The above examples are general ideas

kphillisjr avatar Sep 16 '17 10:09 kphillisjr

@kphillisjr Renamed the issue because ES2015 support is a longer term target so it's not a feature request as such. There isn't a full set of Github issues addressing all the ES2015 feature gaps because that would be a lot of individual issues.

svaarala avatar Sep 16 '17 10:09 svaarala

Related discussion of some implementation details in #1344.

svaarala avatar Sep 16 '17 10:09 svaarala

Does this come true now?

zero-rp avatar Feb 25 '19 22:02 zero-rp

@svaarala

zero-rp avatar Feb 25 '19 22:02 zero-rp

These are not implemented yet.

svaarala avatar Feb 25 '19 22:02 svaarala

aggregation of remaining arguments into a single parameter.This feature is urgently needed.Can you support it as soon as possible?

zero-rp avatar Feb 25 '19 22:02 zero-rp

I can't promise a specific time, it all depends on how much free time I (or others) have to spend on development. In the meanwhile you can use transpiling, e.g. Babel, to get most of the post-ES5.1 features.

svaarala avatar Feb 25 '19 22:02 svaarala