The code is the following:
$('input').click(function(){
window.array[$(this).attr('id')]=true;
console.log('Input id: '+$(this).attr('id')+' - Num:'+window.array.length+
' - Array value:'+window.array[$(this).attr('id')]);
alert(window.array.join('\n'));
});
The behavior is very strange: when the event is fired, in the console I can read Input id: example_id - Num:0 - Array value:true, then in the alert I get undefined (empty array? but the console told me the correct value!).
When I click on another input, exactly the same thing happens, such as the previous event hasn't been fired. It seems that the callback function creates an array every time it's called, but I'm using window object, and I was told that attaching arrays to window object is the same of global vars!
Can you explain me this strange behavior?