Ajax3.14
Ajax3.14

Reputation: 1695

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..

Upvotes: 0

Views: 296

Answers (1)

Jonathan Lonowski
Jonathan Lonowski

Reputation: 123443

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();

Upvotes: 1

Related Questions