Path: csiph.com!.POSTED.208-71-239-109.cust.centrio.cz!not-for-mail From: Cezary Tomczyk Newsgroups: comp.lang.javascript Subject: bind and addEventListener/removeEventListener Date: Tue, 13 Aug 2019 17:28:22 +0200 Organization: csiph.com Internet News Service Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 13 Aug 2019 15:28:23 -0000 (UTC) Injection-Info: csiph.com; posting-host="208-71-239-109.cust.centrio.cz:109.239.71.208"; logging-data="4500"; mail-complaints-to="admin@kev009.com" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 X-Mozilla-News-Host: news://nntpswitch.blueworldhosting.com:119 Content-Language: en-US Xref: csiph.com comp.lang.javascript:37116 Bind https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind creates a new function. Let's say we have #1: 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. -- Cezary Tomczyk http://www.ctomczyk.pl/