Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / bindCallback.js
1 var identity = require('../utility/identity');
2
3 /**
4  * A specialized version of `baseCallback` which only supports `this` binding
5  * and specifying the number of arguments to provide to `func`.
6  *
7  * @private
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.
12  */
13 function bindCallback(func, thisArg, argCount) {
14   if (typeof func != 'function') {
15     return identity;
16   }
17   if (thisArg === undefined) {
18     return func;
19   }
20   switch (argCount) {
21     case 1: return function(value) {
22       return func.call(thisArg, value);
23     };
24     case 3: return function(value, index, collection) {
25       return func.call(thisArg, value, index, collection);
26     };
27     case 4: return function(accumulator, value, index, collection) {
28       return func.call(thisArg, accumulator, value, index, collection);
29     };
30     case 5: return function(value, other, key, object, source) {
31       return func.call(thisArg, value, other, key, object, source);
32     };
33   }
34   return function() {
35     return func.apply(thisArg, arguments);
36   };
37 }
38
39 module.exports = bindCallback;