I created a class in JavaScript which does specific task related key call (key press ) when class is initiated.
Class have a function 'receaveKey' which is referenced by addEventListener like this
document.addEventListener("keypress",this.receaveKey.bind(this));
This works for me but my class have another function "exit" When this is called i want to remove that event listener and i tried this but does work.
document.removeEventListener("keypress",this.receaveKey.bind(this));
Note:- I tried this also but have problem that i cant give a reference of the initiated object of class because i also have to do some task when keys are press using 'functions' of class.
document.addEventListener("keypress",staticClassReceaveKey);
document.removeEventListener("keypress",staticClassReceaveKey);
Note:- i have tried this also
document.addEventListener("keypress",this.receaveKey);
document.removeEventListener("keypress",this.receaveKey);
But does not find any luck as listener is not removed when using methods of class as reference function