I've been facing a challenge in my recent JavaScript project. I've created two animations named DarkWaves and clearScreen. My goal is to pass a function (such as clearScreen) to DarkWaves, let it run its animation, and then execute the passed function. However, I'm struggling to make this work. Upon testing, I discovered that using setTimeout in the code causes an error - callback is not recognized as a function. Even when I checked the typeof callback, it only returned 'defined' unless placed inside a function without setTimeout. To provide more context, I'll include the relevant parts of the code below:
function DarkWaves(callback){//Dark Wave!
function advancingTriangle(whereToGo, rbgValuez){
//drawing logic here
}
if(waveCount === 0){
$('#rightSideBarOuter').hide();//Clearing HTML elements for wave movement
$('#mainAreaOuter').hide();
}
//conditional statements for drawing triangles at different stages of animation
waveCount++;
if(waveCount > 120) waveCount = 0;
if(waveCount !== 0) setTimeout(DarkWaves, 50);
else {callback();}
}
To workaround the issue, I implemented a temporary solution that delays the execution of the desired function after 6500 seconds following the completion of DarkWaves. Any advice or assistance would be greatly appreciated!