Skip to content

Commit 898a3fd

Browse files
jbedardlgalfaso
authored andcommitted
perf($q): only bind Deferred methods when returned publicly from $q.defer
1 parent 9473371 commit 898a3fd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/ng/q.js

+6-5
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, {

0 commit comments

Comments
 (0)