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

Commit ee0f42b

Browse files
committed
perf($q): only bind Deferred methods when returned publicly from $q.defer
1 parent e23c606 commit ee0f42b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/ng/q.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,12 @@ function qFactory(nextTick, exceptionHandler) {
255255
* @returns {Deferred} Returns a new instance of deferred.
256256
*/
257257
var defer = function() {
258-
return new Deferred();
258+
var d = new Deferred();
259+
//Necessary to support unbound execution :/
260+
d.resolve = simpleBind(d, d.resolve);
261+
d.reject = simpleBind(d, d.reject);
262+
d.notify = simpleBind(d, d.notify);
263+
return d;
259264
};
260265

261266
function Promise() {
@@ -328,10 +333,6 @@ function qFactory(nextTick, exceptionHandler) {
328333

329334
function Deferred() {
330335
this.promise = new Promise();
331-
//Necessary to support unbound execution :/
332-
this.resolve = simpleBind(this, this.resolve);
333-
this.reject = simpleBind(this, this.reject);
334-
this.notify = simpleBind(this, this.notify);
335336
}
336337

337338
extend(Deferred.prototype, {
@@ -381,8 +382,9 @@ function qFactory(nextTick, exceptionHandler) {
381382
done = true;
382383
that.$$reject(val);
383384
}
385+
function notify(progress) { that.notify(progress); }
384386
try {
385-
then.call(promiseLike, resolvePromise, rejectPromise, this.notify);
387+
then.call(promiseLike, resolvePromise, rejectPromise, notify);
386388
} catch (e) {
387389
rejectPromise(e);
388390
exceptionHandler(e);

0 commit comments

Comments
 (0)