promise.js
function PendingPromise(queue, onFulfilled, onRejected, deferred) {
  if (!deferred) {
    if (!onFulfilled && !onRejected) { return this; }
    deferred = new Deferred(this.constructor);
  }
  queue.push({
    deferred: deferred,
    onFulfilled: onFulfilled || deferred.resolve,
    onRejected: onRejected || deferred.reject
  });
  return deferred.promise;
}
function PendingPromise(queue, onFulfilled, onRejected, deferred) {
  if (!deferred) {
    if (!onFulfilled && !onRejected) { return this; }
    deferred = new Deferred(this.constructor);
  }
  queue.push({
    deferred: deferred,
    onFulfilled: onFulfilled || deferred.resolve,
    onRejected: onRejected || deferred.reject
  });
  return deferred.promise;
}
function PendingPromise ( queue , onFulfilled , onRejected , deferred ) { if ( ! deferred ) { if ( ! onFulfilled && ! onRejected ) { return this ; } deferred = new Deferred ( this . constructor ) ; } queue . push ( { deferred : deferred , onFulfilled : onFulfilled || deferred . resolve , onRejected : onRejected || deferred . reject } ) ; return deferred . promise ; }
The Pending Promise state. Eventually calls onFulfilled once the promise has
resolved, or onRejected once the promise rejects.

If there is no onFulfilled and no onRejected, returns the current promise to
avoid an promise instance.

@this {!Promise} The current promise
@param {*=} queue The current promise's pending promises queue.
@param {function(*=)=} onFulfilled
@param {function(*=)=} onRejected
@param {Deferred} deferred A deferred object that holds a promise and its
resolve and reject functions. It IS NOT passed when called from
Promise#then to save an object instance (since we may return the current
promise). It IS passed in when adopting the Pending state from the
Pending state of another promise.
@returns {!Promise}
The Pending Promise state . Eventually calls onFulfilled once the promise has resolved or onRejected once the promise rejects .