1 var identity = require('../utility/identity');
4 * A specialized version of `baseCallback` which only supports `this` binding
5 * and specifying the number of arguments to provide to `func`.
8 * @param {Function} func The function to bind.
9 * @param {*} thisArg The `this` binding of `func`.
10 * @param {number} [argCount] The number of arguments to provide to `func`.
11 * @returns {Function} Returns the callback.
13 function bindCallback(func, thisArg, argCount) {
14 if (typeof func != 'function') {
17 if (thisArg === undefined) {
21 case 1: return function(value) {
22 return func.call(thisArg, value);
24 case 3: return function(value, index, collection) {
25 return func.call(thisArg, value, index, collection);
27 case 4: return function(accumulator, value, index, collection) {
28 return func.call(thisArg, accumulator, value, index, collection);
30 case 5: return function(value, other, key, object, source) {
31 return func.call(thisArg, value, other, key, object, source);
35 return func.apply(thisArg, arguments);
39 module.exports = bindCallback;