Hi, first things first, please take a second to check out the page on the
link below.
http://bookofjavascript.com/Chapter13/Assignment.html
In this page, you are supposed to click on the "Make Happiness Bounce"
button to make the smiley face start bouncing and then you can click the
"Stop that Smiley!" button to stop it.
What I find odd about this example is that if I click the "Make Happiness
Bounce" button 5 times the bouncing speeds up and then if I click on the
"Stop that Smiley!" button 5 times the bouncing slow down and stop! I think
I know why it speeds up but what I don't understand is why it slows down.
How is this happening? According to me, the "clearTimeo ut" call does not do
anything special to handle things this way. All it does is the following:
"clearTimeout(t heTimeOut)", where the "theTimeOut " variable is just an
integer!
If you ask me, the "clearTimeout(t heTimeOut)" call should *only* be able
stop the *last* "setTimeout " call but it shouldn't be able to stop previous
calls to "setTimeout " calls
The reason I say this is because previous references to "setTimeout " calls
where stored on the "theTimeOut " variable but this variable is overridden
every time a new call to the "setTimeout " occurs. So how can the
"clearTimeout(t heTimeOut)" know the history of the values that were stored
on the "theTimeOut " variable to be able to stop previous "setTimeout " calls?
I am really confused with this behavior, any help explaining the reason for
this behavior is greatly appreciated.
Thanks you.