Last active
August 29, 2015 14:22
-
-
Save toanalien/2a4082e099b87646bccf to your computer and use it in GitHub Desktop.
Scheduling the Execution of Functions Using Timers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var oneSecond = 1000 * 1; // one second = 1000 x 1 ms | |
// setTimeout | |
setTimeout(function() { | |
document.write('<p>Hello there.</p>'); | |
}, oneSecond); | |
// setInterval | |
var setInteval(function(){ | |
document.write('<p>Hello there.</p>'); | |
}, oneSecond); | |
// using setTimeout to defer the execution of a function | |
var timeout = setTimeout(function(){ | |
console.log("Time out !"); | |
}, oneSecond); | |
// using clearTimeout to cancel the execution of a function | |
clearTimeout(timeout); | |
// using setInterval to defer te repetitive of a function | |
var interval = setInterval(function(){ | |
console.log("tick !"); | |
}, 1000); | |
// using clearInterval to cancel the repetitive of a function | |
clearInterval(timeout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment