javascript - A buffer overflow at recursive function -
there function animatetitle()
changes browser title periodic - every 3 seconds.
var animatetitle = function(countmessages) { if (ischattab) { if (animstep) { document.title = "new messages ("+countmessages+") - "+origtitle; } else { document.title = origtitle; } animstep = !animstep; } else { document.title = origtitle; animstep = false; } time_title = setinterval(function(){ animatetitle(countmessages) }, 3000); };
in script param countmessages
changes in realtime , passed function animatetitle
, leads buffer overflow, because function recursive. how fix?
currently, since you're not clearing existing interval every function phone call creating new intervals. should move interval outside function:
var animatetitle = function(countmessages) { if (ischattab) { if (animstep) { document.title = "new messages ("+countmessages+") - "+origtitle; } else { document.title = origtitle; } animstep = !animstep; } else { document.title = origtitle; animstep = false; } }; time_title = setinterval(function(){ animatetitle(countmessages) }, 3000);
javascript jquery recursion
No comments:
Post a Comment