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

Commit dde90e4

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

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/ng/q.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ function qFactory(nextTick, exceptionHandler) {
267267
* @returns {Deferred} Returns a new instance of deferred.
268268
*/
269269
var defer = function() {
270-
return new Deferred();
270+
var d = new Deferred();
271+
//Necessary to support unbound execution :/
272+
d.resolve = simpleBind(d, d.resolve);
273+
d.reject = simpleBind(d, d.reject);
274+
d.notify = simpleBind(d, d.notify);
275+
return d;
271276
};
272277

273278
function Promise() {
@@ -340,10 +345,6 @@ function qFactory(nextTick, exceptionHandler) {
340345

341346
function Deferred() {
342347
this.promise = new Promise();
343-
//Necessary to support unbound execution :/
344-
this.resolve = simpleBind(this, this.resolve);
345-
this.reject = simpleBind(this, this.reject);
346-
this.notify = simpleBind(this, this.notify);
347348
}
348349

349350
extend(Deferred.prototype, {
@@ -368,7 +369,7 @@ function qFactory(nextTick, exceptionHandler) {
368369
if ((isObject(val) || isFunction(val))) then = val && val.then;
369370
if (isFunction(then)) {
370371
this.promise.$$state.status = -1;
371-
then.call(val, fns[0], fns[1], this.notify);
372+
then.call(val, fns[0], fns[1], simpleBind(this, this.notify));
372373
} else {
373374
this.promise.$$state.value = val;
374375
this.promise.$$state.status = 1;

0 commit comments

Comments
 (0)