flw.js
function wrap(fn, args, key) {
    const self = this;

    if (key === undefined && typeof(args) === 'string') {
      key = args;
      args = [];
    }
    if (!args) args = [];

    return function wrapper(context, cb) {
      const copyArgs = args.slice(args);
      copyArgs.unshift(self);
      copyArgs.push(onWrappedDone);
      return fn.bind.apply(fn, copyArgs)();

      function onWrappedDone(err, result) {
        if (err) return cb(err);

        if (key) context[key] = result;
        return cb(null);
      }
    };
  }
function wrap(fn, args, key) {
    const self = this;

    if (key === undefined && typeof(args) === 'string') {
      key = args;
      args = [];
    }
    if (!args) args = [];

    return function wrapper(context, cb) {
      const copyArgs = args.slice(args);
      copyArgs.unshift(self);
      copyArgs.push(onWrappedDone);
      return fn.bind.apply(fn, copyArgs)();

      function onWrappedDone(err, result) {
        if (err) return cb(err);

        if (key) context[key] = result;
        return cb(null);
      }
    };
  }
function wrap ( fn , args , key ) { const self = this ; if ( key === undefined && typeof ( args ) === 'string' ) { key = args ; args = [ ] ; } if ( ! args ) args = [ ] ; return function wrapper ( context , cb ) { const copyArgs = args . slice ( args ) ; copyArgs . unshift ( self ) ; copyArgs . push ( onWrappedDone ) ; return fn . bind . apply ( fn , copyArgs ) ( ) ; function onWrappedDone ( err , result ) { if ( err ) return cb ( err ) ; if ( key ) context [ key ] = result ; return cb ( null ) ; } } ; }
Returns wrapped regular function that stores the result on the context key
@param {function} fn function to wrap
@param {any[]} [args] Array of arguments to pass (optional)
@param {String} [key] name of context key to store the result in (optional)
Returns wrapped regular function that stores the result on the context key