Click me

Click the link once to start a 1-second loop. During that 1 second, click again. Each time you click, you'll trigger an onclick callback that will set x to "interrupted". At some point, the func2 timeout will set x to good. However, if you click the link several times, some of those callbacks will run after func2. An alert will pop up 500ms after the loop to tell you the value of x.

The question is: Is there any way to ensure that the value of x will be good? That is, how can you make func2 run after all the input events that the user caused during func1 have resolved?

Head to http://stackoverflow.com/questions/6391536/dom-input-events-vs-settimeout-setinterval-order if you think you have an answer.