Converting => () => to ES5

388 Views Asked by At

I'm in the process of converting some scripting from from ES6 to ES5 due to a dependency on the system executing the scripts. I'm running into an issue with this particular command:

transition.selectAll('path.hidden-arc')
   .attrTween('d', d => () => middleArcLine(d));

I'm not sure what they're trying to accomplish with the '=> () =>' syntax and am unsure how to convert this to ES5 standard functions. Any help is greatly appreciated.

3

There are 3 best solutions below

1
jason_r On BEST ANSWER

It's using arrow functions to represent a function that returns a function that returns the value from calling the middleArcline function. In ES5 it could look something like this:

transition.selectAll('path.hidden-arc').attrTween('d', function (d) {
    return function () {
        return middleArcLine(d);
    };
});

Note that Babel is a great tool for compiling between different versions of JavaScript

1
Vasanth Gopal On

I guess it's a function calling a function. Try this

transition.selectAll('path.hidden-arc')
   .attrTween('d', function (d) {
                       return function() {
                           return middleArcLine(d)
                       }
                   }
             );

I might be wrong, but just attempting it.

0
Rahul Cv On
transition.selectAll('path.hidden-arc')
   .attrTween('d', function (d) {
                       return function() {
                         return   middleArcLine(d)
                       }
             );