Created
April 26, 2015 10:41
-
-
Save taktran/2617b45365c849aa89fb to your computer and use it in GitHub Desktop.
applyParamsToArgCallback [NOT WORKING]
This file contains 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
"use strict"; | |
var _ = require('lodash'); | |
var utils = {}; | |
/** | |
* Apply the rest of the arguments to the last | |
* item in function arguments (the callback) | |
* | |
* ``` | |
* arguments = [fnArguments, firstParamForCallback, secondParamForCallback, ...]` | |
* | |
* functionArguments = [firstParam, secondParam, ..., callback] | |
* ``` | |
* | |
* @example | |
* | |
* function something() { | |
* utils.applyParamsToCallback(arguments, 1, 2, 3) | |
* // Calls arguments[last](1, 2, 3) | |
* } | |
* | |
*/ | |
utils.applyParamsToArgCallback = function() { | |
var thisArgs = Array.prototype.slice.call(arguments); | |
fnArgs = fnArgs || []; | |
fnArgs = Array.prototype.slice.call(fnArgs); | |
var callback = fnArgs.pop(); | |
var fnParams = _.rest(thisArgs) || []; | |
callback.apply(undefined, fnParams); | |
}; | |
module.exports = utils; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment