File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -566,11 +566,6 @@ function qFactory(nextTick, exceptionHandler) {
566566 throw $qMinErr ( 'norslvr' , "Expected resolverFn, got '{0}'" , resolver ) ;
567567 }
568568
569- if ( ! ( this instanceof Q ) ) {
570- // More useful when $Q is the Promise itself.
571- return new Q ( resolver ) ;
572- }
573-
574569 var deferred = new Deferred ( ) ;
575570
576571 function resolveFn ( value ) {
@@ -586,6 +581,10 @@ function qFactory(nextTick, exceptionHandler) {
586581 return deferred . promise ;
587582 } ;
588583
584+ // Let's make the instanceof operator work for promises, so that
585+ // `new $q(fn) instanceof $q` would evaluate to true.
586+ $Q . prototype = Promise . prototype ;
587+
589588 $Q . defer = defer ;
590589 $Q . reject = reject ;
591590 $Q . when = when ;
Original file line number Diff line number Diff line change @@ -221,6 +221,15 @@ 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+ /*jshint newcap: true */
231+ } ) ;
232+
224233
225234 describe ( 'resolve' , function ( ) {
226235 it ( 'should fulfill the promise and execute all success callbacks in the registration order' ,
You can’t perform that action at this time.
0 commit comments