Parse documentation ( .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
});
?
Parse documentation ( https://www.parse./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
});
?
Share Improve this question asked Jul 21, 2014 at 16:53 Ben WheelerBen Wheeler 7,3742 gold badges48 silver badges58 bronze badges 2-
I'd use native promises and use
Promise.all
which has semantics which are a lot better. – Benjamin Gruenbaum Commented Jul 21, 2014 at 17:03 - How are you sure that Parse.Promises are patible with native promises? – fatuhoku Commented Jan 18, 2016 at 14:33
1 Answer
Reset to default 14You 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
});