开发者

Can I stop JavaScript function execution via global variables?

So I read through this a bit, and it looks like JavaScript functions can't be explicitly killed off mid-run. What if I have a global variable, window.currentlyProcessing that manages this.

function contentsChanged()
{
    if( window.curentlyProcessing == true )
    {
        return;
    }
    window.curentlyProcessing = true;
    // DO STUFF
    windo开发者_JAVA百科w.curentlyProcessing = false;
}

Since contentsChanged gets called a lot, will this effectively stop it from running over itself?


Javascript is single threaded - one function is executed at a time, the function will never "run over itself" to begin with. contentsChanged will get called, will execute until the end, then any other stuff will happen.


That would prevent the logic from running if it's already running. If that's what you need to do, it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜