I have an object defined like this:
Blah = {
hideTimer:null,
setTimer: function() {
this.hideTimer = window.setTimeout(Blah.hidePopupInner, 500);
// must be done via window due to Greasemonkey
},
hidePopupInner: function() {
log("This? " + this);
},
hidePopupInnerPublic: function() {
Blah.hidePopupInner();
}
}
The problem is that the 'this' in killTimer is not set to Blah. If I change the line to say
this.hideTimer = window.setTimeout(Blah.hidePopupInnerPublic, 500);
then the 'this' is pointing to Blah so the hideTimer can be utilized.
Making a 'public' method for each method solves the problem, but there must be an easier solution...?
Note: This is all in Greasemonkey, but I think it's a general Javascript question.