How to call a function from ...spread?

0 like 0 dislike
13 views
In the case where it is necessary to pass multiple callback functions, how to call them out ...spread? And is it right to use ... for this?
by | 13 views

3 Answers

0 like 0 dislike
The question is absolutely incomprehensible, but I'll try play the guessing game:
const f = (...callbacks) => { // spread collects arguments into an array, // so you can work with them as an array callbacks.forEach((callback) => callback()); } f( () => console.log(1), () => console.log(2), () => console.log(42), );
by
0 like 0 dislike
If you pass multiple variables, and collect and spread, you get an array of variables, so here, only the elements of the array will function.
by
0 like 0 dislike
Why not do an array of functions?

function f (callbacks) { for (let i = 0; i < callbacks.length; i++) { callbacks[i](); } } f ( [ _ => console.log(0), _ => console.log(1), _ => console.log(10), ] );
by

Related questions

0 like 0 dislike
3 answers
asked Aug 11, 2019 by zwezew
0 like 0 dislike
2 answers
asked Jun 9, 2019 by tokmaganbet
0 like 0 dislike
2 answers
asked May 21, 2019 by campus1
110,608 questions
257,186 answers
0 comments
32,846 users