This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +13
-5
lines changed
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) {
566
566
throw $qMinErr ( 'norslvr' , "Expected resolverFn, got '{0}'" , resolver ) ;
567
567
}
568
568
569
- if ( ! ( this instanceof Q ) ) {
570
- // More useful when $Q is the Promise itself.
571
- return new Q ( resolver ) ;
572
- }
573
-
574
569
var deferred = new Deferred ( ) ;
575
570
576
571
function resolveFn ( value ) {
@@ -586,6 +581,10 @@ function qFactory(nextTick, exceptionHandler) {
586
581
return deferred . promise ;
587
582
} ;
588
583
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
+
589
588
$Q . defer = defer ;
590
589
$Q . reject = reject ;
591
590
$Q . when = when ;
Original file line number Diff line number Diff line change @@ -221,6 +221,15 @@ describe('q', function() {
221
221
expect ( typeof promise . finally ) . toBe ( 'function' ) ;
222
222
} ) ;
223
223
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
+
224
233
225
234
describe ( 'resolve' , function ( ) {
226
235
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