W3C home > Mailing lists > Public > www-dom@w3.org > April to June 2012

Re: Add extra argument to addEventListener with the context

From: Glenn Maynard <glenn@zewt.org>
Date: Fri, 15 Jun 2012 18:03:54 -0500
Message-ID: <CABirCh8eUWkznPVq+0u3eacrgeXek921dW56V+_2bGCcC-odaA@mail.gmail.com>
To: Elliott Sprehn <esprehn@gmail.com>
Cc: Boris Zbarsky <bzbarsky@mit.edu>, www-dom@w3.org
On Fri, Jun 15, 2012 at 4:32 PM, Elliott Sprehn <esprehn@gmail.com> wrote:

> I don't think this is bloat. Having the extra argument has shown itself to
> be useful across millions of lines of JS at Google, and you can see all the
> var self = this; stuff on open source projects everywhere.

"Lots of code at Google does this" is only saying that it's a convention
within Google, not that it's actually a good idea.  I never use "var self =
this"; that's what bind() is for.

I don't think this is a reasonable argument. Lots of things are trivial,
> like doing var self = this; or writing your own bind implementation (why
> bother having bind build in?). Saying "it's trivial" and therefore we
> shouldn't do it would have prevented lots of features in the platform.

It's perfectly reasonable to bind the function yourself; it's no harder
than binding it from within the owner class.

The event API--at least in this detail--is clean and consistent with other
callback APIs.  You don't seem to be trying to fix a problem with the event
API; you're trying to work around problems in other things by adding stuff
to the event API.  It wouldn't make sense to add this to addEventListener
without adding it to setTimeout, setInterval, Canvas.toBlob, and so on.
Don't add a whole second paradigm for method binding--fix the real problems
at their source.

Glenn Maynard
Received on Friday, 15 June 2012 23:04:23 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:00 UTC