I'm a bit confused in a situation,
given the sample code here where I'm loading several urls, and connected the event Listener:
var pages= Array();
var loading= Array();
for(i=0; i < urls.length; i++){
var page =new WebPage(urls[i]);
page.onLoadStarted = function() {
loading[i]= true;
console.log('Loading started');
};
pages[i]=page;
}
I have 5 urls, and I get 5 times "Loading started" in the console output, however the loading array had only one value defined (true) all the rest are "undefined";
Looks like when the event is triggered loading[i]= true;
uses the last value of I to access the array instead of using its address. How can I fix that ?
I've tried adding a property to the page object, but same thing happens;
Here is what I've tried:
var pages= Array();
for(i=0; i < urls.length; i++){
var page =new WebPage(urls[i]);
page.onLoadStarted = function() {
page.loading= true;
console.log('Loading started');
};
pages[i]=page;
}