Skip to content

Commit aea4fa0

Browse files
committed
fixing behavior of nbind binding
1 parent cfbc9e4 commit aea4fa0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

q.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,14 +1410,13 @@ function nfbind(callback/*, ...args */) {
14101410
}
14111411

14121412
Q.nbind = nbind;
1413-
function nbind(callback/*, ... args*/) {
1414-
var baseArgs = array_slice(arguments, 1);
1413+
function nbind(callback, thisArg /*, ... args*/) {
1414+
var baseArgs = array_slice(arguments, 2);
14151415
return function () {
14161416
var nodeArgs = baseArgs.concat(array_slice(arguments));
14171417
var deferred = defer();
14181418
nodeArgs.push(deferred.makeNodeResolver());
14191419

1420-
var thisArg = this;
14211420
function bound() {
14221421
return callback.apply(thisArg, arguments);
14231422
}

spec/q-spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,11 +1919,12 @@ describe("node support", function () {
19191919
describe("nbind", function () {
19201920

19211921
it("binds this, and mixes partial application with complete application", function () {
1922-
return Q.nbind(function (a, b, c, d, callback) {
1923-
callback(null, this + a + b + c + d);
1924-
}, 1, 2).call(3, 4, 5)
1925-
.then(function (fifteen) {
1926-
expect(fifteen).toBe(15);
1922+
return Q.nbind(function (a, b, c, callback) {
1923+
console.log(this, arguments);
1924+
callback(null, this + a + b + c);
1925+
}, 1, 2).call(3 /* effectively ignored as fn bound to 1 */, 4, 5)
1926+
.then(function (twelve) {
1927+
expect(twelve).toBe(12);
19271928
});
19281929
});
19291930

0 commit comments

Comments
 (0)