Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Starting to integrate object properties

  • Loading branch information...
commit 22a57c50926ed88d872d60366d77a299fdef16c2 1 parent ad2de45
@briancavalier briancavalier authored
Showing with 27 additions and 8 deletions.
  1. +27 −8 when.js
View
35 when.js
@@ -427,7 +427,7 @@ define(function() { "use strict";
deferred.resolve(results);
} else {
- deferred.promise.always(function complete() {
+ deferred.promise.always(function() {
resolver = rejecter = handleProgress = noop;
});
@@ -448,24 +448,43 @@ define(function() { "use strict";
// Another strategy would be to use the original position of
// the corresponding promise.
results.push(val);
-
if (!--toResolve) {
deferred.resolve(results);
}
};
- // TODO: Replace while with forEach
- for(i = 0; i < len; ++i) {
- if(i in promisesOrValues) {
- when(promisesOrValues[i], resolve, reject, progress);
- }
- }
+ forEach(promisesOrValues, function(p) {
+ when(p, resolve, reject, progress);
+ });
}
return when(deferred, callback, errback, progressHandler);
});
}
+ var forEach = Array.prototype.forEach
+ ? function(array, lambda) {
+ return array.forEach(lambda);
+ }
+ : function (array, lambda) {
+ var i, len;
+ for(i = 0, len = array.length; i < len; ++i) {
+ if(i in array) {
+ lambda(array[i], i);
+ }
+ }
+ };
+
+ var owns = Object.prototype.hasOwnProperty;
+
+ function forEachKey(object, lambda) {
+ for(var p in object) {
+ if(owns.call(object, p)) {
+ lambda(object[p], p);
+ }
+ }
+ }
+
/**
* Return a promise that will resolve only once all the supplied promisesOrValues
* have resolved. The resolution value of the returned promise will be an array
Please sign in to comment.
Something went wrong with that request. Please try again.