diff --git a/lib/async.js b/lib/async.js index 52f5f2c51..312000fe0 100644 --- a/lib/async.js +++ b/lib/async.js @@ -1147,29 +1147,27 @@ }; - var _applyEach = _restParam(function _applyEach(eachfn, fns, args) { - var go = _restParam(function(args) { - var that = this; - var callback = args.pop(); - return eachfn(fns, function (fn, _, cb) { - fn.apply(that, args.concat([cb])); - }, - callback); + function _applyEach(eachfn) { + return _restParam(function(fns, args) { + var go = _restParam(function(args) { + var that = this; + var callback = args.pop(); + return eachfn(fns, function (fn, _, cb) { + fn.apply(that, args.concat([cb])); + }, + callback); + }); + if (args.length) { + return go.apply(this, args); + } + else { + return go; + } }); - if (args.length) { - return go.apply(this, args); - } - else { - return go; - } - }); + } - async.applyEach = _restParam(function (args) { - return _applyEach.apply(null, [async.eachOf].concat(args)); - }); - async.applyEachSeries = _restParam(function (args) { - return _applyEach.apply(null, [async.eachOfSeries].concat(args)); - }); + async.applyEach = _applyEach(async.eachOf); + async.applyEachSeries = _applyEach(async.eachOfSeries); async.forever = function (fn, callback) {