define (global) variables for all your watches, timeouts, and in intervals you plan to set
give the name a suffix, like xyzWId or xyzWHndl for watch handles
initialized them with false at declaration (optional, any falsy evaluating value will do: undefined, null, 0, "", false)
always use the variable when setting the Watch / Interval / Timeout
always use the following construct when clearing a Watch / Interval / Timeout - mostly I use a function or method of an object where I have a simplified invocation interface to make sure I do not misspell the variable name and other things. Most of the time there is more that has to go on at the same time with the particular clear...(), and that goes nicely in such a function or method.... and some times these things have even to go conditioned on the ...Id as well.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Good practice - I use - is:
false
at declaration (optional, any falsy evaluating value will do: undefined, null, 0, "", false)always use the following construct when clearing a Watch / Interval / Timeout - mostly I use a function or method of an object where I have a simplified invocation interface to make sure I do not misspell the variable name and other things. Most of the time there is more that has to go on at the same time with the particular
clear...()
, and that goes nicely in such a function or method.... and some times these things have even to go conditioned on the ...Id as well.PS: clear...() returns undefined, which is falsy and does the expected job.