Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use of <code>setInterval</code> is discouraged. For an explanation, read here: <a href="http://bonsaiden.github.com/JavaScript-Garden/#other.timeouts" rel="nofollow">http://bonsaiden.github.com/JavaScript-Garden/#other.timeouts</a></p> <p>To summarise the problem:</p> <p><code>setInterval</code> fires the event at a regular interval, regardless of what else is happening on the page.</p> <p>However, Javascript is not multi-threaded: it can only run one code sequence at a time. If <code>setInterval</code> is triggered while another code sequence is being run, the new code sequence will be blocked until the previous one is finished, and will wait for it.</p> <p>If this happens repeatedly, you can end up with a large number of events waiting to be run.</p> <p>You're using <code>alert()</code> to display your messages. <code>alert()</code> causes the code execution sequence to pause until the user responds to the message, but keeps it locked, so that other events cannot run their code. This is a particular problem for <code>setInterval</code>, because it fires new events at the specified time, regardless of whether something else is blocking the script.</p> <p>The solution is to use <code>setTimeout</code> instead of <code>setInterval</code>.</p> <p><code>setTimeout</code> is only triggered once, but it is easy to tell it to trigger itself again inside its own function, so you can get the same effect as <code>setInterval</code>, but with much more control. Your code can wait until after the <code>alert()</code> has been accepted by the user before triggering the next event, which means that you won't get the problem of cascading events that can happen with <code>setInterval</code>.</p> <p>Hope that helps explain things. The link I mentioned at the beginning is also very helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload