Path: csiph.com!weretis.net!feeder7.news.weretis.net!news.roellig-ltd.de!open-news-network.org!news4.open-news-network.org!.POSTED.129.235.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: bind and addEventListener/removeEventListener Date: Tue, 13 Aug 2019 20:58:36 +0200 Organization: PointedEars Software (PES) Lines: 29 Message-ID: <4464615.GXAFRqVoOG@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Info: news4.open-news-network.org; posting-host="129.235.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch:178.197.235.129"; logging-data="13675"; mail-complaints-to="usenet@exeter.123backup.de" User-Agent: KNode/4.14.10 X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. 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: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.