Created
November 9, 2012 20:32
-
-
Save timkg/4048050 to your computer and use it in GitHub Desktop.
Code from page 3 of the book Async Javascript
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 clickCount = 0, link; | |
link = document.getElementById('masochist') | |
link.innerHTML = 'How many times can you click me?'; | |
link.onclick = function(){ | |
clickCount++; | |
link.onclick = function(){ clickCount++; }; | |
start = new Date(); | |
while (new Date() - start < 5000) {} | |
console.log(clickCount); // this will always be 1 | |
setTimeout(function(){ | |
link.innerHTML = 'You clicked me ' + clickCount + ' times. Ow!'; | |
}, 0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment