Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

Left closed in review as "Duplicate" by andrewJames, Davi, Satpal
Post Closed as "Duplicate" by Cerbrus javascript Users with the javascript badge or a synonym can single-handedly close questions as duplicates and reopen them as needed.
Some spelling changes in code and other stuff
Source Link
pushkin
  • 10.4k
  • 16
  • 65
  • 112

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asynchronousProcess(callbackFunction() {
 alert(i);
 });
}

I am trying to display a series of alerts, showing in orderthe numbers 0 through 10. The problem is that by the time the call backcallback function is triggered, the loop has already gone through a few iterations and it displays a higher value of ii. Any recommendationrecommendations on how to fix this?

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asynchronousProcess(callbackFunction() {
 alert(i);
 });
}

I am trying to display a series of alerts, showing in order numbers 0 through 10. The problem is that by the time the call back function is triggered the loop has already gone through a few iterations and it displays a higher value of i. Any recommendation on how to fix this?

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asynchronousProcess(callbackFunction() {
 alert(i);
 });
}

I am trying to display a series of alerts showing the numbers 0 through 10. The problem is that by the time the callback function is triggered, the loop has already gone through a few iterations and it displays a higher value of i. Any recommendations on how to fix this?

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asycronouseProcessasynchronousProcess(callBackFunctioncallbackFunction() {
 alert(i);
 });
}

What I would like thisam trying to display is a series of alerts, showing in order numbers 0 through 10. The problem is that by the time the call back function is triggered the loop has already gone through a few iterations and it displays a higher value of i. Any recommendation on how to fix this?

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asycronouseProcess(callBackFunction() {
 alert(i);
 });
}

What I would like this to display is a series of alerts showing numbers 0 through 10. The problem is that by the time the call back function is triggered the loop has already gone through a few iterations and it displays a higher value of i. Any recommendation on how to fix this?

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asynchronousProcess(callbackFunction() {
 alert(i);
 });
}

I am trying to display a series of alerts, showing in order numbers 0 through 10. The problem is that by the time the call back function is triggered the loop has already gone through a few iterations and it displays a higher value of i. Any recommendation on how to fix this?

Source Link
Ben Pearce
  • 7.1k
  • 19
  • 77
  • 130

Asynchronous Process inside a javascript for loop

I am running an event loop of the following form:

var i;
var j = 10;
for (i = 0; i < j; i++) {
 asycronouseProcess(callBackFunction() {
 alert(i);
 });
}

What I would like this to display is a series of alerts showing numbers 0 through 10. The problem is that by the time the call back function is triggered the loop has already gone through a few iterations and it displays a higher value of i. Any recommendation on how to fix this?

lang-js

AltStyle によって変換されたページ (->オリジナル) /