Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32274

Re: remove listener

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: remove listener
Date 2017-01-23 20:14 +0100
Organization PointedEars Software (PES)
Message-ID <4757540.29KlJPOoH8@PointedEars.de> (permalink)
References <_N2dnVScZPU0SR_FnZ2dnUU7-IXNnZ2d@westnet.com.au> <4137428.rnE6jSC6OK@PointedEars.de> <ebKdnbTeM4E0nB7FnZ2dnUU7-T3NnZ2d@westnet.com.au> <w8ydnVs1-tbith7FnZ2dnUU7-TXNnZ2d@westnet.com.au> <4v-dnTZ7z6m9rR7FnZ2dnUU7-K1j4p2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> On 21/01/2017 8:35 PM, Andrew Poulos wrote:
>> How can I remove the listener if the handler is
>>   this.show.bind(this, i)
>> ?
> 
> My bad for wasting everyone's time. MDN tells me that bind creates a new
> bound function. I just stored a reference to it and used that instead.

That is the correct solution.  It is usually called an “event registry”.

I think it is unfortunate that, with the exception of event listeners added 
using event-handler properties, there is no built-in way without having to 
do that.  At least the built-in Map type (which allows object references as 
keys directly) introduced with ECMAScript 2015 now allows one to register 
event listeners per DOM object instead of per DOM object serialization and, 
if necessary, linear search.

-- 
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 | Find similar | Unroll thread


Thread

remove listener Andrew Poulos <ap_prog@hotmail.com> - 2017-01-21 14:25 +1100
  Re: remove listener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-21 06:07 +0100
    Re: remove listener Andrew Poulos <ap_prog@hotmail.com> - 2017-01-21 17:37 +1100
      Re: remove listener Andrew Poulos <ap_prog@hotmail.com> - 2017-01-21 20:35 +1100
        Re: remove listener Andrew Poulos <ap_prog@hotmail.com> - 2017-01-21 20:55 +1100
          Re: remove listener Scott Sauyet <scott@sauyet.com> - 2017-01-21 19:24 +0000
          Re: remove listener Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-23 20:14 +0100

csiph-web