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

Re: Add extra argument to addEventListener with the context

From: Elliott Sprehn <esprehn@gmail.com>
Date: Fri, 15 Jun 2012 14:03:57 -0700
Message-ID: <CAPJYB1ighZpo09xy8m2=-u8Zd1HFfyWico+LAGpSTqB4N9pK4g@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: www-dom@w3.org
On Fri, Jun 15, 2012 at 10:48 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 6/15/12 1:33 PM, Elliott Sprehn wrote:
>> Why would I want the methods on my class to be assignable?
> You wouldn't, but the point is that the class would do this at creation
> time.

It's not that simple, because methods are likely on the prototype object
defined in advance so there's no chance to call bind(this) before it's
marked as not-writable.

This can cause other badness like breaking argument introspection for
frameworks since the method no longer returns it's source when you do

> Or is your issue that you want to take a class you don't control and use
> one of its methods as the listener?

Yes, this may also be the case.

Adding this extra parameter cuts down on the amount of manual tracking you
need to do, removes the need to allocate an extra Function object, and
removes boilerplate code (it's very common to see people use var self =
this; in projects).

- Elliott
Received on Friday, 15 June 2012 21:04:46 UTC

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