guard.js 283 B

12345678910
  1. var _ = require("./_");
  2. _.Promise.prototype.guard = function (type, onRejected) {
  3. return this.catch(function (reason) {
  4. if (reason instanceof type && onRejected)
  5. return onRejected(reason);
  6. else
  7. return _.Promise.reject(reason);
  8. });
  9. };