+ 7
How can i pass arguments for function while using requestAnimationFrame like setTimeout ? [Solved]
10 Réponses
+ 5
I hope this will understands you
https://code.sololearn.com/WrQLVhpIS26o/?ref=app
+ 11
Abhay hmm ok I got it now.. I'll try to find a way out :)
+ 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
+ 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
+ 5
Abhay welcome 😇
+ 4
v@msi😏😏 thank you very much
+ 3
Just use function in function
requestAnimationFrame(function() { repeat (e); }) it works for me
+ 3
Aditya that definitely works fine for setTimeout but not for requestAnimationFrame
+ 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!
+ 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