Re: [whatwg/dom] Adding a `context` property to the listener options. (#472)

Thanks Lea.

My concern on this matter is actually not about performance, rather about the ability to cleanup listeners whenever it's needed.

You named arrow functions, and indeed these are in the same category of runtime bound functions.
```js
// no way to remove that listener later on
el.addEventListener(type, anyCallback.bind(anyObject));

// also no way, if we use an arrow function
el.addEventListener(type, event => this.method(event));
```

Custom Elements are also a very common example where methods are attached on `connectedCallback` and removed on `disconnectedCallback`, specially those events that might be triggered synthetically and, while "_offline_" should never result in any sort of action.

This is just an example on how the community still easily fail with the current patterns:
https://www.npmjs.com/package/ts-custom-elements

![screenshot from 2017-06-20 12-42-50](https://user-images.githubusercontent.com/85749/27626182-0c495e82-5bdf-11e7-890a-7d511912457d.png)

With this proposed change developers will have an easy migration pattern and, on top of that, it can be polyfilled through WeakMap, where available, or Expando.



-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/472#issuecomment-311585072

Received on Wednesday, 28 June 2017 07:54:09 UTC