Re: Add extra argument to addEventListener with the context

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
instance.method.toString()


>
> 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