Skip to content

Commit

Permalink
fixing behavior of nbind binding
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpadbury committed Mar 10, 2013
1 parent cfbc9e4 commit aea4fa0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,14 +1410,13 @@ function nfbind(callback/*, ...args */) {
}

Q.nbind = nbind;
function nbind(callback/*, ... args*/) {
var baseArgs = array_slice(arguments, 1);
function nbind(callback, thisArg /*, ... args*/) {
var baseArgs = array_slice(arguments, 2);
return function () {
var nodeArgs = baseArgs.concat(array_slice(arguments));
var deferred = defer();
nodeArgs.push(deferred.makeNodeResolver());

var thisArg = this;
function bound() {
return callback.apply(thisArg, arguments);
}
Expand Down
11 changes: 6 additions & 5 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1919,11 +1919,12 @@ describe("node support", function () {
describe("nbind", function () {

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

Expand Down

0 comments on commit aea4fa0

Please sign in to comment.