Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 377c810

Browse files
committedDec 17, 2015
fix($q): make instanceof work for $q promises
1 parent 9bb184d commit 377c810

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎src/ng/q.js

+4
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ function qFactory(nextTick, exceptionHandler) {
586586
return deferred.promise;
587587
};
588588

589+
// Let's make the instanceof operator work for promises, so that
590+
// `new $q(fn) instanceof $q` would evaluate to true.
591+
$Q.prototype = Promise.prototype;
592+
589593
$Q.defer = defer;
590594
$Q.reject = reject;
591595
$Q.when = when;

‎test/ng/qSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ describe('q', function() {
221221
expect(typeof promise.finally).toBe('function');
222222
});
223223

224+
it('should support the instanceof operator', function() {
225+
/*jshint newcap: false */
226+
var promise = new q(noop);
227+
expect(promise instanceof q).toBe(true);
228+
promise = q(noop);
229+
expect(promise instanceof q).toBe(true);
230+
});
231+
224232

225233
describe('resolve', function() {
226234
it('should fulfill the promise and execute all success callbacks in the registration order',

0 commit comments

Comments
 (0)
This repository has been archived.