Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(var i = 0; i < list.length; i++){
- mc_cli.get(list[i], function(err, response) {
- do_something(i);
- });
- }
- do_something((function(x){return x})(i))
- var create_closure = function(i) {
- return function() {
- return i;
- }
- }
- do_something(create_closure(i)())
- list.forEach(function(listItem, index){
- mc_cli.get(listItem, function(err, response) {
- do_something(index);
- });
- });
- var total = parsed_result.list.length;
- var count = 0;
- for(var i = 0; i < total; i++){
- (function(foo){
- mc_cli.get(parsed_result.list[foo], function(err, response) {
- do_something(foo);
- count++;
- if (count > total - 1) done();
- });
- }(i));
- }
- // You can guarantee that this function will not be called until ALL of the
- // asynchronous functions have completed.
- function done() {
- console.log('All data has been loaded :).');
- }
- function createCallback(i) {
- return function(){
- do_something(i);
- }
- }
- for(var i = 0; i < list.length; i++){
- mc_cli.get(list[i], createCallback(i));
- }
- for(let i = 0; i < list.length; i++){
- mc_cli.get(list[i], function(err, response) {
- do_something(i);
- });
- }
- var arr = ['Hello', 'World', 'Javascript', 'Async', ':)'];
- for( var i = 0; i < arr.length; i++) {
- (function(index){
- setTimeout(function(){
- console.log(arr[index]);
- }, 500);
Add Comment
Please, Sign In to add comment