Is there a way to record the value of an index when a listener is being created, so that that same value is used when the listener function is called? : <p>When an event listener function is called, the value of the index is no longer the same value as when the listener was created</p>

<p>I'm creating all the markers and their listeners through iteration. however when 'infowindow.open(map, marker[i]);' is called after the iteration, 'i' has a different value and opens a different marker's infowindow. How can I make this point to the marker being clicked?</p>

<pre><code>google.maps.event.addListener(marker[i], 'click', function(){
  infowindow.open(map, marker[i]);
}
</code></pre>

<p>I can see why this is happening but I'm not sure how to get around it. 'infowindow.open(map, marker[i]);' is not called until the marker is clicked, and by that stage i has a different value.</p>
