Better way to maintain this reference on event listener functions

Andrea Giammarchi andrea.giammarchi at
Mon May 9 13:41:37 UTC 2016

Raising a concern about `addEventListener` and its context probably made me
think it was rather a WHATWG concern.

Anyway, I don't know why you had to point out the `class` keyword ... I
mean ....

class SomeClass {
  constructor(someNode) {
    someNode.addEventListener('click', this);
  onclick(e) {
    alert(; // SomeClass
  handleEvent(e) {
    this['on' + e.type](e);

There you go

Best Regards

On Mon, May 9, 2016 at 2:38 PM, Mark Kennedy <mkay581 at> wrote:

> Wow that's so ironic because [I posted this same idea](
> (literally
> copied and pasted) in WHATWG's "DOM land" and they told me this was an
> es-discuss issue. So which is it?
> Oh and thanks for the code sample but it uses the old prototypical method
> of replicating a class by creating a function which is now not the most
> efficient way (there's the `class` keyword). And I don't see how what
> you're doing isn't any different from a roundabout way of what I did. I
> already know about the `handleEvent()` stuff, I like that it's available
> and its polyfills. They are great, but my original question is to implement
> sugar so that you don't have to use polyfills or the `handleEvent()`.
> --
> mark
> Sent while riding a hoverboard...
> :)
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list