简体   繁体   English

JavaScript回调函数不起作用

[英]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. blinkyblinky只是逗号运算符的第二个值,并且没有任何反应。

And, if it's not a callback, but rather just needs to be called after each function in funqueue , then just: 而且,如果它不是回调,而是只需要在funqueue每个函数之后funqueue ,则只需:

funqueue.shift();
blinky();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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