Right. And that warrants clear(er) documentation and not deprecation,
as there is no other way to handle partial application in event
handlers.

On Mar 14, 7:10 pm, kangax <kan...@gmail.com> wrote:
> On Mar 14, 11:43 am, Tobie Langel <tobie.lan...@gmail.com> wrote:
>
> > I'd like to see how we can combine all of this elegantly with
> > bindAsEventListener and curry.
>
> I personally don't understand the need for `bindAsEventListener` at
> all. It's the most misunderstood method in Prototype. Its scope of use
> is so narrow that it makes sense to deprecate it.
>
> To explain:
>
> `bindAsEventListener` guarantees that an event object is being passed
> as a first argument to an event handler. The problem is that every
> single use of `bindAsEventListener` that I've seen is used with
> `observe`. When `observe` uses `attachEvent` (in MSHTML DOM) it
> already does pass event object as a first argument to event handler
> (which makes `event || window.event` in `bindAsEventListener`
> redundant). `bind` suffices most of the time, except when a partial
> application is used (or, of course, if you're not using `observe` in
> the first place, but an intrinsic event attribute).
>
> Another problem is that `bindAsEventListener` is almost *never* used
> with partial application (look at Scriptaculous, for example, or
> practically any other snippet on the web).
>
> What this all means is that these 2 expressions are functionally
> identical (considering that they are called from within the same
> execution context):
>
> myElement.observe('click', onClick.bind(this));
> myElement.observe('click', onClick.bindAsEventListener(this));
>
> And there's absolutely no need to use the latter one.
>
> myElement.observe('click', onClick.bindAsEventListener(this, 'foo',
> 'bar'));
>
> - on the other hand, ensures that an event handler, when called, will
> have an `event` object as a first argument (i.e. "foo" and "bar" will
> be second and third arguments, rather than first and second). This is
> exactly what's misunderstood about this method.
>
> [...]
>
> --
> kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to