I would like to stop a timer after I delete the variable containing the function that ran it.
The following works but requires an extra step:
foo = (function() {
function doSomething() {
console.log('I am running ')
timer1 = setTimeout(doSomething, 2000)
}
doSomething()
console.log('timer is #' + (bob))
return {
stopTimer: function() {
clearTimeout(timer1)
return true
}
}
})()
//
// let it run a while..
//
// later, stop it .. this works but is an extra step
foo.stopTimer()
// no more logs .. success
That is, it stops the timer. However the REAL OBJECTIVE is just to do this:
foo = <new code like a new version overwriting the existing one>
-- or less desirably --
foo = null
And have the timer(s) stop. Is this possible and if so how?