Created
October 16, 2014 10:53
-
-
Save itarato/644803197d7a277910fd to your computer and use it in GitHub Desktop.
Paramerized callback generator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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