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.
精彩评论