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

Commit 2006bdb

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

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, {
@@ -365,8 +366,9 @@ function qFactory(nextTick, exceptionHandler) {
365366
var that = this;
366367
function resolve(val) { that.$$resolve(val); }
367368
function reject(val) { that.$$reject(val); }
369+
function notify(progress) { that.notify(progress); }
368370
try {
369-
promiseLike.then(resolve, reject, this.notify);
371+
promiseLike.then(resolve, reject, notify);
370372
} catch (e) {
371373
reject(e);
372374
exceptionHandler(e);

0 commit comments

Comments
 (0)