Re: Better event listeners

using an object also allows for future scope creep. Returning a function
makes the API simple and reduces complexity.

However almost none of the existing host APIs are higher order functions (I
can't think of a single API that returns a function) so it probably doesn't
fit with the style.

However returning an object with a method stop is ambigious, returning an
object with a method removeEventListener is verbose. I guess an object with
a cancel method would make sense.


On Tue, Jan 8, 2013 at 3:32 PM, Glenn Maynard <glenn@zewt.org> wrote:

> On Tue, Jan 8, 2013 at 5:23 AM, Anne van Kesteren <annevk@annevk.nl>wrote:
>
>> On Mon, Jan 7, 2013 at 6:18 PM, Jake Verbaten <raynos2@gmail.com> wrote:
>> > Emphasis being on that `.on(...)` returns some kind of token that can be
>> > used to remove the listener so we don't have to keep a reference to the
>> > listener ourself somewhere.
>>
>> I think that makes a lot of sense. I like the idea of just returning a
>> function reference.
>>
>
> Returning an object with a method is a more common pattern on the
> platform.  It also allows adding related features in the future without
> contortions (eg. Prototype's also has start(), to re-add the listener).
>
> --
> Glenn Maynard
>
>

Received on Tuesday, 8 January 2013 23:39:10 UTC