Hi,

> Have you, by any chance, done any "memory tests" on this, T.J.?

Nothing rigorous or replicable/quotable.

Reading between the lines, you're thinking about premature
optimization, aren't you? :-)  One does definitely need to beware of
PO, but any time you're creating a closure that's going to have any
kind of lifespan -- an event handler, for instance -- I don't think
it's PO to look at what's in scope and consider the effects of that
stuff enduring for the lifespan of the closure.  A lot of closures
used with each() are create-and-throw-away, no need to worry about
those.  Even Ajax callbacks usually only hang around a few seconds.
But enduring things like UI event handlers, I think it's worth minimal
effort making sure you're not holding onto a bunch of unnecessary
stuff.

As always, it's a balancing act, writing good code from the outset on
the one hand, optimizing prematurely on the other...

-- T.J. :-)

On Oct 31, 2:56 am, kangax <[EMAIL PROTECTED]> wrote:
> On Oct 30, 2:30 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > > 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.
>
> Good catch : )
>
>
>
> > > 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. :-)
>
> Interesting.
> There are usually so many closures created (specially in larger
> applications), that I have never considered minimizing their presence.
> Have you, by any chance, done any "memory tests" on this, T.J.?
>
> > --
> > T.J. Crowder
> > tj / crowder software / com
>
> [snip]
>
> --
> 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