mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
In some cases, the type of Error thrown by minErr is meaningful, such as in $q where a TypeError is sometimes required. This fix allows providing an error constructor as the second argument to minErr, which will be used to construct the error that gets returned by the factory function.
27 lines
833 B
JavaScript
27 lines
833 B
JavaScript
/* global qFactory: false */
|
|
'use strict';
|
|
|
|
var isFunction = function isFunction(value){return typeof value == 'function';};
|
|
var isPromiseLike = function isPromiseLike(obj) {return obj && isFunction(obj.then);};
|
|
var isObject = function isObject(value){return value != null && typeof value === 'object';};
|
|
var minErr = function minErr (module, constructor) {
|
|
return function (){
|
|
var ErrorConstructor = constructor || Error;
|
|
throw new ErrorConstructor(module + arguments[0] + arguments[1]);
|
|
};
|
|
};
|
|
|
|
var $q = qFactory(process.nextTick, function noopExceptionHandler() {});
|
|
|
|
exports.resolved = $q.resolve;
|
|
exports.rejected = $q.reject;
|
|
exports.deferred = function () {
|
|
var deferred = $q.defer();
|
|
|
|
return {
|
|
promise: deferred.promise,
|
|
resolve: deferred.resolve,
|
|
reject: deferred.reject
|
|
};
|
|
};
|