Sunday, May 19, 2024
178
rated 0 times [  185] [ 7]  / answers: 1 / hits: 7544  / 10 Years ago, mon, july 21, 2014, 12:00:00

Parse documentation ( https://www.parse.com/docs/js/symbols/Parse.Promise.html#.when ) explains that when using Parse.Promise.when, it is kosher to specify an array of promises:



var p1 = Parse.Promise.as(1);
var p2 = Parse.Promise.as(2);
var p3 = Parse.Promise.as(3);

var promises = [p1, p2, p3];
Parse.Promise.when(promises).then(function(r1, r2, r3) {
console.log(r1); // prints 1
console.log(r2); // prints 2
console.log(r3); // prints 3
});


...which is sweet!



But, do you really have to list every single promise response in your then() function? Not really feasible if you have an array of promises of unknown size, and not very DRY!



Can I do this?



Parse.Promise.when(promises).then(function(responses) {
console.log(responses[0]); // prints 1
console.log(responses[1]); // prints 2
console.log(responses[2]); // prints 3
});


?


More From » parse-platform

 Answers
6

You can make use of JavaScript's builtin special variable, arguments like this



Parse.Promise.when(promises).then(function() {
console.log(arguments[0]); // prints 1
console.log(arguments[1]); // prints 2
console.log(arguments[2]); // prints 3
});

[#43726] Sunday, July 20, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyasiaalmap

Total Points: 294
Total Questions: 107
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
;