Note that there are some explanatory texts on larger screens.

plurals
  1. POusing jQuery .promise() to call clearInterval()
    primarykey
    data
    text
    <p>I have been experimenting a lot with setInterval and clearInterval recently, for creating my own custom effects and one of the things that I have been working on is an efficient way to clear an interval whilst staying out of the global scope. I am trying to improve readability and explore possible performance boosts by using .promise() to call clearInterval() (the below is an example of what I'm trying to do):</p> <pre><code>//caller is a collection of elements function performEffect(caller) { var interval = setInterval(function() { caller.next(); }, 500); caller.promise().done(function() { interval = clearInterval(interval); }); } </code></pre> <p>Up until recently, I had been setting and clearing the interval using an embedded function (example):</p> <pre><code>function performEffect(caller) { var interval; var count = 0; var len = caller.length; if (count &gt;= len) { interval = clearInterval(interval); } var tmr = function () { interval = setInterval(function () { effectFunciton(count++); }, 100); } } </code></pre> <p>P.S. I'm sorry for not posting the original - my versioning system was corrupted. Also, I know that this example is kind of silly, since I could easily use a for-loop or a .each(), but it's just an example - I do have instances where I do not want to use a loop.</p> <p>This is my first post, so I apologize ahead of time if I do something different from the accepted practice. Please let me know if there is anything I can do to improve my posts in the future - I'm always open to constructive criticism :)</p> <p>Thanks!</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.
 

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