I can assure you - with 100% certainty - that there is no difference
whatsoever between named functions and anonymous functions with regard to
scoping rules and closures. They both follow exactly the same rules.

What does matter is where the functions are located in the source code -
which functions are nested inside which other functions. When one function
is nested inside another, the inner function can access the variables and
parameters from the outer function - even if the outer function has already
returned at the time that the inner function is called. The functions' names
(or lack of names) don't change this.

In the case of Arun's original code snippet from this thread, there simply
was no inner function at all to create a closure. It sounds like Arun has
fixed that, but the fix would work exactly the same whether the inner
function has a name or not.

-Mike

> From: Rossko
> 
> Or to put it another way,
> The 'i' based loop runs and kicks off several geocoder requests.
> Your i appears to be global, can't tell from the snippet.
> When the loop finishes, i is incremented beyond the end of stories[].
> Ages later, in javascript terms, a response comes back and 
> the function is called now, processing with the now-invalid i value.
> 
> I'm a bit suspicious of using a named function in this context too ..
> see this post
>
http://groups.google.com/group/Google-Maps-API/browse_thread/thread/3234e0d0
b988563f/8a2632e609fba762?lnk=gst&q=anonymous+callback+function#8a2632e609fb
a762
> 
> cheers, Ross K


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to