简体   繁体   中英

Javascript callback function not working

I am using this function to store animation functions and call it one by one for sequential animation.

I am not sure what I am missing in the below code. I wanted it to be a callback function.

currently this method runs only once.

function treasure(){

    var blinky = function ()
    {
        if (funqueue.length > 0)
        {
            ((funqueue.shift())(), blinky);
        }
        else { return }

    }
     blinky();

}

Thanks..

If it's intended as a callback, it should be passed within the calling parenthesis rather than after. (Also, the extra, wrapping parenthesis aren't really necessary.)

funqueue.shift()(blinky);

As is, blinky is just the 2nd value for the comma operator and nothing happens with it.

And, if it's not a callback, but rather just needs to be called after each function in funqueue , then just:

funqueue.shift();
blinky();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM