Mark Kennedy (2016-05-09T09:29:42.000Z)
mkay581 at gmail.com (2016-05-09T17:07:17.607Z)
Sorry if I've missed any previous requests for this feature, but is there any goal to allow callbacks passed to event listeners to keep their `this` context without having to store a reference to the this-binded event listener first? I frequently find myself doing this in my class methods: ```javascript this.el = document.createElement('div'); this.listener = this.onClick.bind(this); // store a reference just to bind the `this` to remove it later this.el.addEventListener('click', this.listener) ``` only to ensure the correct listener mapping gets removed later on in a `destroy`-like function with this code: ```javascript this.el.removeEventListener('click', this.listener); ``` A few years ago I would've never thought of a good reason to add such sugar, but now that JS is moving forward with class declarations, it seems more warranted now.
mkay581 at gmail.com (2016-05-09T17:06:59.812Z)
Sorry if I've missed any previous requests for this feature, but is there any goal to allow callbacks passed to event listeners to keep their `this` context without having to store a reference to the this-binded event listener first? I frequently find myself doing this in my class methods: ```javascript this.el = document.createElement('div'); this.listener = this.onClick.bind(this); // store a reference just to bind the `this` and remove it later this.el.addEventListener('click', this.listener) ``` only to ensure the correct listener mapping gets removed later on in a `destroy`-like function with this code: ```javascript this.el.removeEventListener('click', this.listener); ``` A few years ago I would've never thought of a good reason to add such sugar, but now that JS is moving forward with class declarations, it seems more warranted now.
mkay581 at gmail.com (2016-05-09T17:06:36.559Z)
Sorry if I've missed any previous requests for this feature, but is there any goal to allow callbacks passed to event listeners to keep their `this` context without having to store a reference to the this-binded event listener first? I frequently find myself doing this in my class methods: ```javascript this.el = document.createElement('div'); this.listener = this.onClick.bind(this); // store a reference just to bind the `this` this.el.addEventListener('click', this.listener) ``` only to ensure the correct listener mapping gets removed later on in a `destroy`-like function with this code: ```javascript this.el.removeEventListener('click', this.listener); ``` A few years ago I would've never thought of a good reason to add such sugar, but now that JS is moving forward with class declarations, it seems more warranted now.