window.addEventListener(\'unload\', function(e)
{
MyClass.shutdown();
window.removeEventListener(\'unload\', /* how to refer to this function? */);
}, false);
>
I haven't tried this, but how about moving the removeEventListener method call into MyClass itself. The method won't be anonymous, but you won't be polluting the global namespace and it will be part of the class it's manipulating. You can even make it "private". I'm not sure what your style is, but I'd write it something like this:
var MyClass = function(){
var self = this;
self.shutdown = function(){
window.removeEventListener('unload',self.shutdown,false);
};
self.initialize = function() {
window.addEventListener('unload',self.shutdown,false);
};
return self;
};
var myObject = new MyClass();
myObject.initialize();
I guess it depends on what MyClass does and how you use it.