There are two issues here, first, even though the stopListen method is called, the event still got posted,
The posted code has syntax errors:
> document.removeEventListener "keydown", KeyboardInputManager.prototype.listener
should be:
document.removeEventListener("keydown", KeyboardInputManager.prototype.listener);
Why this doesn't work can't be determined without seeing more code.
I wanted to call some other prototype methods of A, but the this var in it is the document that is passed to the listener
Because when a function is attached as a listener using addEventListener, then this within the function is the DOM object that the listener was attached to. If you want some other object, you can set it in the call, e.g.
A.prototype.listen = function() {
document.addEventListener("keydown", function() {
KeyboardInputManager.prototype.listener.call(A);
});
}
However, how you don't have a function to reference to remove the listener. See Suman's answer for ideas on how to fix that (i.e. attached a named function that calls the listener and sets this to the value you want).