Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit af4b66c

Browse files
author
bluepnume
committed
fix($q): Use extend to avoid overwriting prototype
This patch uses `extend()` to add prototypal methods to `Promise` and `Deferred`, to avoid having to set `constructor` manually on the overwritten prototype.
1 parent 6b4f2fc commit af4b66c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/ng/q.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ function qFactory(nextTick, exceptionHandler) {
270270
this.$$state = { status: 0 };
271271
}
272272

273-
Promise.prototype = {
274-
constructor: Promise,
275-
273+
extend(Promise.prototype, {
276274
then: function(onFulfilled, onRejected, progressBack) {
277275
var result = new Deferred();
278276

@@ -294,7 +292,7 @@ function qFactory(nextTick, exceptionHandler) {
294292
return handleCallback(error, false, callback);
295293
}, progressBack);
296294
}
297-
};
295+
});
298296

299297
//Faster, more basic than angular.bind http://jsperf.com/angular-bind-vs-custom-vs-native
300298
function simpleBind(context, fn) {
@@ -341,9 +339,7 @@ function qFactory(nextTick, exceptionHandler) {
341339
this.notify = simpleBind(this, this.notify);
342340
}
343341

344-
Deferred.prototype = {
345-
constructor: Deferred,
346-
342+
extend(Deferred.prototype, {
347343
resolve: function(val) {
348344
if (this.promise.$$state.status) return;
349345
if (val === this.promise) {
@@ -407,7 +403,7 @@ function qFactory(nextTick, exceptionHandler) {
407403
});
408404
}
409405
}
410-
};
406+
});
411407

412408
/**
413409
* @ngdoc method

0 commit comments

Comments
 (0)