Methods
loop(ms, callback, oldLoopopt, nullable) → {Object}
Setup a loop for repeated execution of a callback, kills old loop if wished to prevent overlapping loops.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ms |
Number | time in milliseconds until execution |
||
callback |
function | callback function to execute after ms |
||
oldLoop |
Object | Number |
<optional> <nullable> |
null | if set, kills the loop before setting up new one |
- Source:
- See:
Throws:
error if ms is not positive or if callback is not a function
Returns:
new loop
- Type
- Object
Example
const loop = loop(250, function(){ document.body.classList.add('brightred'); });
const loop = loop(100, function(){ document.body.classList.add('brightgreen'); }, loop);