Quantcast
Channel: User Thomas - Stack Overflow
Viewing all articles
Browse latest Browse all 39

How to pass values to a callback function at the time of the request call?

$
0
0

I have the following situation:

var foo = [ 0, 1, 2 ]for (var i in foo) {    Asyncstuff.get(URI).on('response', function(res) { console.log(i); } });}

Because the .on('response',...) is called in an asynchronous manner, the output will most likely be

222

Is there a possibility to pass the value of i at the time the .get() is called to the callback function?


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>