On Thursday 22 March 2007 19:06, Michael Peters wrote:
> [EMAIL PROTECTED] wrote:
> > Great, but is it safe when using multiple Request?
>

If you're using closures inside a loop, there is a second gotcha to watch out 
for, if you're enclosing a variable that gets modified in subsequent passes 
of the loop. I wrote up a short example of this a while back, here:

http://dave.sunwheeltech.com/wordpress/2006/04/30/more-closure-strangeness/

Best way to avoid this is to get into Prototype's array methods, as the 
iterator function will isolate each pass of the loop into a separate 
execution context automatically.

Dave

> Closures capture a reference to the variable. So it will always refer to
> the same variable. That's only usually a problem if your variable is in the
> global scope. If your var is scoped to a previous enclosing sub then it
> will be fine.

-- 
----------------------
Author
Ajax in Action http://manning.com/crane
Ajax in Practice http://manning.com/crane2
Prototype & Scriptaculous in Action http://manning.com/crane3

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to