- I'm not asking abou how to make a function in ES6 syntax using =>, I was asking about why the return function was added in the middle of function. I searched more and I found out that it's how currying function is coded.*
I tried to get some idea from Observable codes to build a graph simulating the behavior of dropping balls.
I expected Observable share the same syntax as Javascript D3 but, actually I realized that it uses different, its own syntax which is somewhat similar to JS.
What does return x=>{ ..... continue...} mean?
For the actual code from Observable is as below.
return x => {
const l = bisect.left(circles, x - radius);
const r = bisect.right(circles, x + radius, l);
let y = 0;
for (let i = l; i < r; ++i) {
const {x: xi, y: yi} = circles[i];
const x2 = (xi - x) ** 2;
const y2 = (yi - y) ** 2;
if (radius2 > x2 + y2) {
y = yi + Math.sqrt(radius2 - x2) + 1e-6;
i = l - 1;
continue;
}
}
circles.splice(bisect.left(circles, x, l, r), 0, {x, y});
return y;
};
I also wonder about what 'replay', 'continue'and 'yield' are in the following code. I hope to implement the codes here in Javascript...