AudioKeys
AudioKeys copied to clipboard
Is there a mechanism to remove listeners?
Good point: not really! To clarify, are you looking to remove up
/down
listeners that you've previously added, or the DOM event listeners as well?
If you're in a pinch and you want to remove an up
/down
handler, you can safely remove it from the AudioKeys._listeners.down
or AudioKeys._listeners.up
array. So for example (haven't tested this out but hopefully you get the idea):
// setup
var keyboard = new AudioKeys();
keyboard.down(downHandler);
// when you want to remove it
keyboard._listeners.down.splice(
keyboard._listeners.down.indexOf(downHandler),
1
);
Methods for removing handlers would be a nice addition (I'll happily accept PRs); something like removeUp
and removeDown
that does this internally.
If on the other hand you want to remove the DOM events (and teardown the whole module), we'd have to add a method.