I have the following piece of code:
var i = 0;
for (var anchor in window.globals.html.anchors) {
     var value = window.globals.html.anchors[anchor];
     value.addEventListener('click', function(i) {
          var currData = window.globals.data[i],
              data_clientId = 0;
          if (currData.client_product_id !== undefined) {
              data_clientId = currData.getAttribute('data_clientId');
          } else if (currData.product_id !== undefined) {
              data_clientId = currData.product_id;
          }
          Statistics.send(data_clientId);
          window.open(window.globals.data[i].url, '_blank');
     }(i));
     i++;
}
Which means I want to access global array by interator inside the click event listener. If I don't pass no i to the click event I get the maximum number possible in each iteration, as i would be a global variable.
But right here it seems that all iterations of click events are invoke before clicking anything, onload.
Why is that so, what's wrong?
 
    