Skip to content

Instantly share code, notes, and snippets.

@itarato
Created October 16, 2014 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itarato/644803197d7a277910fd to your computer and use it in GitHub Desktop.
Save itarato/644803197d7a277910fd to your computer and use it in GitHub Desktop.
Paramerized callback generator.
/**
* Parameterized callback generator.
*
* @param callback
* The callable function to call.
* @param ...
* All additional parameters will be arguments of the callback, as well as the default callback arguments:
* Structure: callback(givenArg1, ..., givenArgN, callbackArg1, ..., callbackArgM);.
* @returns {Function}
*/
var callbackWithParam = function ( callback ) {
var args = [].slice.apply(arguments);
args.shift();
return function () {
var callbackArgs = [].slice.apply(arguments);
args = args.concat(callbackArgs);
callback.apply(null, args);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment