Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
How to call a function from ...spread? - code-flow.club | Q&A

How to call a function from ...spread?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
65 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 | 65 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 22, 2019 by campus1
110,608 questions
257,186 answers
0 comments
35,179 users