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 10:33:47 -0700
Message-ID: <CAPJYB1iLgey7uUV7vNr4VJ1dkV3VuNBOyGFqQtOuU6_W9LN-dw@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: www-dom@w3.org
Why would I want the methods on my class to be assignable? For instance
assuming a new class syntax I'd want every method on an instance to be
totally locked down.

On Fri, Jun 15, 2012 at 10:29 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 6/15/12 1:21 PM, Elliott Sprehn wrote:
>
>> Google Closure supports an additional final argument to addEventListener
>> that's the context the method is called with:
>>
>> target.addEventListener(event, fn, capture, context)
>>
>> So you could do
>>
>> target.addEventListener(event, this.handleClick, false, this);
>>
>> and later
>>
>> target.removeEventListener(**event, this.handleClick, false, this);
>>
>> It'd be nice to get native support since it makes adding and removing
>> listeners easier.
>>
>
> How is this different from doing:
>
>  this.handleClick = this.handleClick.bind(this);
>
> once and then doing?:
>
>  target.addEventListener(event, this.handleClick, false);
> ...
>  target.removeEventListener(**event, this.handleClick, false);
>
> -Boris
>
>
Received on Friday, 15 June 2012 17:34:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:09 GMT