javascript - Adding new first argument, then applying original arguments -
i using map map set of functions so:
function runwaterfall(consumer, fns, cb) { fns = fns.map(function (fn) { return function () { fn(consumer, arguments); } }); async.waterfall(fns, cb); } so can see, add "consumer" first argument every function fn, don't believe syntax right.
perhaps better:
function runwaterfall(consumer, fns, cb) { fns = fns.map(function (fn) { return function () { fn.apply(null,[consumer, arguments]); } }); async.waterfall(fns, cb); } i doubt either of these correct
you can use function.prototype.bind not set this context, provide arguments. close apply, call function while bind return function argument pre-filled:
fns = fns.map(function (fn) { return fn.bind( null, consumer ) });
Comments
Post a Comment