My code
// do ajax request and get JSON response
for (var i = 0; i < data.results.length; i++) {
result = data.results[i];
// do stuff and c
Try this:
with ({ mark: marker }) {
google.maps.event.addListener(mark, 'click', function() {
createWindow(mark.id);
});
}
An example that demonstrates the use of with:
for (var i = 0; i < 10; i++) {
setTimeout(function() { console.log(i); }, 1000);
}
The above will log 10 ten times.
for (var i = 0; i < 10; i++) {
with ({ foo: i }) {
setTimeout(function() { console.log(foo); }, 1000);
}
}
This will log 0 to 9, as desired, thanks to with introducing a new scope.
JavaScript 1.7 has a let statement that is nicer, but until that is widely supported, you can use with.
And use var for your variables.