function then(state, value, callbacks, onFulfilled, onRejected) {
  var newPromise, resolve, reject, result;

  newPromise = new Promise(function(res, rej) {
    resolve = res;
    reject = rej;
  });

  callbacks.push(function(state, value) {
    try {
      if (state == FULFILLED) {
        if (isFunction(onFulfilled)) {
          result = onFulfilled(value);
        } else {
          result = value;
        }
      } else if (state == REJECTED) {
        if (isFunction(onRejected)) {
          result = onRejected(value);
        } else {
          reject(value);
        }
      }
      resolve(result);
    } catch (e) {
      reject(e);
    }
  });

  // Value could be calculated already
  executeCallbacks(state, value, callbacks);

  return newPromise;
}
/**
 * Creates a new Promise, whose value is calculated later.
 * @returns {object} new Promise
 */
Creates a new Promise, whose value is calculated later.
@returns {object} new Promise
Creates a new Promise whose value is calculated later . @returns { object } new Promise
function then(state, value, callbacks, onFulfilled, onRejected) {
  var newPromise, resolve, reject, result;
  newPromise = new Promise(function(res, rej) {
    resolve = res;
    reject = rej;
  });
  callbacks.push(function(state, value) {
    try {
      if (state == FULFILLED) {
        if (isFunction(onFulfilled)) {
          result = onFulfilled(value);
        } else {
          result = value;
        }
      } else if (state == REJECTED) {
        if (isFunction(onRejected)) {
          result = onRejected(value);
        } else {
          reject(value);
        }
      }
      resolve(result);
    } catch (e) {
      reject(e);
    }
  });
  executeCallbacks(state, value, callbacks);
  return newPromise;
}
function then ( state , value , callbacks , onFulfilled , onRejected ) { var newPromise , resolve , reject , result ; newPromise = new Promise ( function ( res , rej ) { resolve = res ; reject = rej ; } ) ; callbacks . push ( function ( state , value ) { try { if ( state == FULFILLED ) { if ( isFunction ( onFulfilled ) ) { result = onFulfilled ( value ) ; } else { result = value ; } } else if ( state == REJECTED ) { if ( isFunction ( onRejected ) ) { result = onRejected ( value ) ; } else { reject ( value ) ; } } resolve ( result ) ; } catch ( e ) { reject ( e ) ; } } ) ; executeCallbacks ( state , value , callbacks ) ; return newPromise ; }
Creates a new Promise, whose value is calculated later.
Creates a new Promise whose value is calculated later .
// Value could be calculated already