Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37124
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: bind and addEventListener/removeEventListener |
| Date | 2019-08-13 20:58 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <4464615.GXAFRqVoOG@PointedEars.de> (permalink) |
| References | <qiukun$4ck$1@csiph.com> |
Cezary Tomczyk wrote:
> document.body.addEventListener('click', myExampleClass.method.bind(this));
>
> and then:
>
> document.body.removeEventListener('click', myExampleClass.method);
>
> based on my research it should not be correct as the function created by
> bind is different than the original passed by reference in
> document.body.removeEventListener.
>
> If it is not correct then the approach like:
>
> var myRef = myExampleClass.method.bind(this);
>
> document.body.addEventListener('click', myRef);
> document.body.removeEventListener('click', myRef);
>
> should be more appropriate, I guess.
>
> Need some thoughts on that.
Your logic is sound and correct.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bind and addEventListener/removeEventListener Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2019-08-13 17:28 +0200
Re: bind and addEventListener/removeEventListener Julio Di Egidio <julio@diegidio.name> - 2019-08-13 08:43 -0700
Re: bind and addEventListener/removeEventListener Julio Di Egidio <julio@diegidio.name> - 2019-08-13 11:29 -0700
Re: bind and addEventListener/removeEventListener Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2019-08-13 20:43 +0200
Re: bind and addEventListener/removeEventListener Julio Di Egidio <julio@diegidio.name> - 2019-08-13 11:48 -0700
Re: bind and addEventListener/removeEventListener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-08-13 20:58 +0200
Re: bind and addEventListener/removeEventListener Julio Di Egidio <julio@diegidio.name> - 2019-08-13 12:36 -0700
csiph-web