Skip to content

Instantly share code, notes, and snippets.

@timkg
Created November 9, 2012 20:32
Show Gist options
  • Save timkg/4048050 to your computer and use it in GitHub Desktop.
Save timkg/4048050 to your computer and use it in GitHub Desktop.
Code from page 3 of the book Async Javascript
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