From aea4fa065563addb658509e775a1b0d09396dc64 Mon Sep 17 00:00:00 2001 From: davidpadbury Date: Sun, 10 Mar 2013 12:43:47 -0400 Subject: [PATCH] fixing behavior of nbind binding --- q.js | 5 ++--- spec/q-spec.js | 11 ++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/q.js b/q.js index 8e85a616..9f43a545 100644 --- a/q.js +++ b/q.js @@ -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); } diff --git a/spec/q-spec.js b/spec/q-spec.js index 7173ef46..a69a92e8 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -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); }); });