I’m aware that’s it very common to use this as much as possible when writing ActionScript 3 code (http://www.daveoncode.com/2009/01/07/we-should-always-use-actionscripts-this-keyword/).
But what should be done if you’re writing anonymous functions, which don’t have appropriate this matching.
x.addEventListener(Event.WHATEVER, function(event:*) {
// When this callback fires, there is a fail:
// because there is no 'this' at this point.
// INVALID!
this.someAction();
});
I saw some recommendations on writing something like:
var self = this;
and then using self in the code of your anonymous functions, but this seems weird.
What’s your opinion on this question (for example, do you have something about it in your coding standard)?
We have a similar approach (so this isn’t an answer as much as it is affirmation of your approach):
Of course, the purist might say that you shouldn’t be adding listeners in a manner that prevents you from removing them! That said, we use this convention in other places where we use inner functions outside the context of a listener.