How can i pass arguments for function while using requestAnimationFrame like setTimeout ? [Solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

How can i pass arguments for function while using requestAnimationFrame like setTimeout ? [Solved]

https://code.sololearn.com/W5Nwbt146uHN/?ref=app

7th Aug 2020, 12:29 PM
Abhay
Abhay - avatar
10 Answers
+ 5
I hope this will understands you https://code.sololearn.com/WrQLVhpIS26o/?ref=app
7th Aug 2020, 2:08 PM
v@msi😉
v@msi😉 - avatar
+ 11
Abhay hmm ok I got it now.. I'll try to find a way out :)
7th Aug 2020, 1:57 PM
Aditya
Aditya - avatar
+ 10
I don't have much idea about js..but I have tried this :) function repeat() { // Do anything requestAnimationFrame(repeat); } requestAnimationFrame(repeat); Call it once to kick it off, and your function recursively calls itself. Hope this helps.. I may be wrong anyone can crrt me I will be happy :D
7th Aug 2020, 1:12 PM
Aditya
Aditya - avatar
+ 10
I think multiple arguments can be passed by this.. function repeat(par1, par2) { // do something here } setTimeout(example, 5000, 'msg1', 'msg2'); //msg 1, msg2 are parameters Again not sure if it works in your case :D
7th Aug 2020, 1:35 PM
Aditya
Aditya - avatar
+ 5
Abhay welcome 😇
7th Aug 2020, 3:16 PM
v@msi😉
v@msi😉 - avatar
+ 4
v@msi😏😏 thank you very much
7th Aug 2020, 3:08 PM
Abhay
Abhay - avatar
+ 3
Just use function in function requestAnimationFrame(function() { repeat (e); }) it works for me
7th Aug 2020, 1:32 PM
v@msi😉
v@msi😉 - avatar
+ 3
Aditya that definitely works fine for setTimeout but not for requestAnimationFrame
7th Aug 2020, 1:40 PM
Abhay
Abhay - avatar
+ 3
v@msi😏😏 thks ,but I have never tried that function into function thing,if you can provide a full example of how to do pls!
7th Aug 2020, 1:48 PM
Abhay
Abhay - avatar
+ 2
That's what I am doing ,but if you were to pass arguments to repeat function how would you ? in setTimeout it is easy but I am not able to understand how to work with requestAnimationFrame Like: function repeat(e) { console.log(e) requestAnimationFrame(repeat); } requestAnimationFrame(repeat); e here is an argument that callback function(repeat) takes and logs out the time after which next repaint will happen if I am right but any other additional argument you pass to requestAnimationFrame(check,5, 6) and then use parameters to access in following function, function repeat(e,f,g){ Console.log(e,f,g) } f and g values are logged out as undefined
7th Aug 2020, 1:19 PM
Abhay
Abhay - avatar