promise.js
function tryCatchDeferred(deferred, fn, arg) {
  var promise = deferred.promise;
  var resolve = deferred.resolve;
  var reject = deferred.reject;
  return function() {
    try {
      var result = fn(arg);
      doResolve(promise, resolve, reject, result, result);
    } catch (e) {
      reject(e);
    }
  };
}
function tryCatchDeferred(deferred, fn, arg) {
  var promise = deferred.promise;
  var resolve = deferred.resolve;
  var reject = deferred.reject;
  return function() {
    try {
      var result = fn(arg);
      doResolve(promise, resolve, reject, result, result);
    } catch (e) {
      reject(e);
    }
  };
}
function tryCatchDeferred ( deferred , fn , arg ) { var promise = deferred . promise ; var resolve = deferred . resolve ; var reject = deferred . reject ; return function ( ) { try { var result = fn ( arg ) ; doResolve ( promise , resolve , reject , result , result ) ; } catch ( e ) { reject ( e ) ; } } ; }
Creates a function that will attempt to resolve the deferred with the return
of fn. If any error is raised, rejects instead.

@param {!Deferred} deferred
@param {function(*=)} fn
@param {*} arg
@returns {function()}
Creates a function that will attempt to resolve the deferred with the return of fn . If any error is raised rejects instead .