Can we pass a function with parameters as a callback function ? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Can we pass a function with parameters as a callback function ?

19th Apr 2021, 5:40 PM
LIGHT
LIGHT - avatar
2 Respostas
+ 5
No if you do that it will call the function you put as an argument itself, plus that beats the purpose
19th Apr 2021, 5:53 PM
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ - avatar
0
You can pass arguments to a callback by wrapping it in another function. I've made a little, basic demo. https://code.sololearn.com/Wn4Y7HVdUkcU/?ref=app Being able to handle arguments is very useful for callbacks, just as for other functions. For example, several in-built array methods take a callback function with multiple parameters. E.g. map, filter, reduce etc.
20th Apr 2021, 2:32 AM
CamelBeatsSnake
CamelBeatsSnake - avatar