Re: Add extra argument to addEventListener with the context

On Fri, Jun 15, 2012 at 2:15 PM, Glenn Maynard <glenn@zewt.org> wrote:

> On Fri, Jun 15, 2012 at 4:03 PM, Elliott Sprehn <esprehn@gmail.com> wrote:
>
>> 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()
>>
>
> You're asking to bloat one API (DOM events) to work around limitations of
> other APIs, but it wouldn't stop here; JavaScript uses callbacks
> extensively,...
>

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.


>  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.
>>
>
> That's trivial; just create a binding of the function yourself.  You don't
> have to store it in the external class.
>

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.

- Elliott

Received on Friday, 15 June 2012 21:33:33 UTC