> The "lost" context is easily "fixed":
>
> sendState(email, $F('save-comments'),
> sph.fire.bind(sph).curry(doneEvent));

bind() accepts additional parameters for the function, so you don't
need the curry:

    sendState(
        email,
        $F('save-comments'),
        sph.fire.bind(sph, doneEvent)
    );

curry is really just bind without the context param.

> I'd suggest to simply pass a function as in your first example:
>
> sendState(email, $F('save-comments'), function()
> { sph.fire(doneEvent) });

Yes, it's definitely clearer.  The only thing would be if there's a
lot of data referenced in the context where this is occurring that
he's trying to avoid involving in a closure.  One of the great things
about bind and curry is that they help you avoid creating closures
when you don't want to. :-)
--
T.J. Crowder
tj / crowder software / com

On Oct 30, 5:51 am, kangax <[EMAIL PROTECTED]> wrote:
> On Oct 29, 8:41 pm, Hook <[EMAIL PROTECTED]> wrote:
>
> > I have a function that contains the following statement:
>
> >         sendState(email, $F('save-comments'),
> >              function () { sph.fire(doneEvent); });
>
> > The last argument is a function that gets called from within
> > sendState.  This works fine.
>
> > But when I change this to
>
> >       sendState(email, $F('save-comments'),
> > sph.fire.curry(doneEvent));
>
> > it fails on both Firefox & IE.  I thought these two statements would
> > be the same.  What am I missing?
>
> These function differ in the way they are called. Former one is called
> in a context of `sph' while latter one is called in a context of a
> global object (e.g. window). The "lost" context is easily "fixed":
>
> sendState(email, $F('save-comments'),
> sph.fire.bind(sph).curry(doneEvent));
>
> Both `curry' and `bind' make the final function a bit slower and look
> somewhat cryptic : )
> I'd suggest to simply pass a function as in your first example:
>
> sendState(email, $F('save-comments'), function()
> { sph.fire(doneEvent) });
>
>
>
> > --
> > Hook
>
> --
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to