I got re-energized in javascript thanks to a great talk from a colleague today.
I came home and elected to try out my new l33t skillz, and promptly hit a roadblock due to the dreaded scoping of "this".
Basically the scenario is this; I have an object MyObject with a function Reminder(), which gets called after a 10 second delay. The reminder pops up, and when the user closes the reminder, the object's ResetTimer() function gets called. The last line of the ResetTimer function that I was trying to do was:
setInterval( this.Reminder, 10000), and the Reminder function acts on "this". The problem is that when the Reminder function gets called, "this" becomes window. The easy fix, as outlined in this great blog post by Alex Le is to use a closure function, passing the instance into the closure:
setInterval(function(that) { that.Reminder(); }, 10000, this);
The last step was to refactor up to the prototype and all was good!