Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #40458
| Path | csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: removing event listener |
| Date | Mon, 11 Oct 2021 16:42:22 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 29 |
| Message-ID | <87ee8rbmap.fsf@bsb.me.uk> (permalink) |
| References | <8audnTTCjcPf5P78nZ2dnUU7-KnNnZ2d@westnet.com.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader02.eternal-september.org; posting-host="21a644e6b7b9371e1c94688240884ca4"; logging-data="21461"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nqvBo9u4ZKBWabTfRiw45WVwhnQ+yUwA=" |
| Cancel-Lock | sha1:bQkc+MtGBt+RYgho5pOV8jw8dy8= sha1:LTgdpAqe29S+9HQMEQXKu9PYHQk= |
| X-BSB-Auth | 1.5a9cf2203d88734dcfdd.20211011164222BST.87ee8rbmap.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.javascript:40458 |
Show key headers only | View raw
Andrew Poulos <ap_prog@hotmail.com> writes:
> I Have this
>
> Interaction = function() {
> ...
> };
>
> Interaction.prototype.action = function() {
> let me = this;
> ...
> document.addEventListener('keydown', me.action.bind(me));
> };
>
> Interaction.prototype.reaction = function() {
> let me = this;
> ...
> document.removeEventListener('keydown', me.action.bind(me));
> };
>
> but when 'reaction' gets called the 'keydown' event listener doesn't
> get removed. How can I remove the event listener within 'reaction'?
bind creates a new anonymous function but you can only remove an event
function by passing in the exact same function you passed when calling
addEventListener. You'll have to store that function value somewhere.
--
Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
removing event listener Andrew Poulos <ap_prog@hotmail.com> - 2021-10-11 10:37 +1100
Re: removing event listener Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-11 16:42 +0100
Re: removing event listener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-10-12 22:43 +0200
Re: removing event listener Julio Di Egidio <julio@diegidio.name> - 2021-10-11 09:46 -0700
Re: removing event listener JJ <jj4public@gmail.com> - 2021-10-12 22:21 +0700
Re: removing event listener Julio Di Egidio <julio@diegidio.name> - 2021-10-12 09:57 -0700
Re: removing event listener John Harris <niam@jghnorth.org.uk.invalid> - 2021-10-12 18:13 +0100
Re: removing event listener Julio Di Egidio <julio@diegidio.name> - 2021-10-12 16:05 -0700
Re: removing event listener John Harris <niam@jghnorth.org.uk.invalid> - 2021-10-13 18:10 +0100
Re: removing event listener John Harris <niam@jghnorth.org.uk.invalid> - 2021-10-12 18:15 +0100
Re: removing event listener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-10-12 22:55 +0200
csiph-web