You can also add an id to the markers as you create them, then catch
the click event and return the marker by id. While using closure is
simpler to implement, catching the event leaves a smaller footprint in
memory, as you can just test the event to see if it is a marker rather
than listening to every marker object. I have an implementation using
prototypejs, but I have not gotten around to coding this in regular
js, but I think others have posted on this topic elsewhere in the
forum.

Josh

On Dec 22, 12:47 am, Rossko <[email protected]> wrote:
> > I just read briefly about function closures and I think I have an idea
> > of what is going on. If I create a function outside of the outer
> > function(addMarkers) is there any way to know which marker was clicked
> > on?
>
> Read some more and have a play with code.  Taking code out to another
> function and passing arguments to it is indeed the key to achieving
> closure.  The clever part of closure, is that it will "capture" passed-
> in data at the time that you create the event listener for each
> marker ; when a listener is actually triggered, that data will be
> available by the magic of closure.  Could be a marker object or
> whatever else you want.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

Reply via email to