* The base implementation of `_.createCallback` without support for creating * "_.pluck" or "_.where" style callbacks. * * @private * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @par
(func, thisArg, argCount)
| 35995 | * @returns {Function} Returns a callback function. |
| 35996 | */ |
| 35997 | function baseCreateCallback(func, thisArg, argCount) { |
| 35998 | if (typeof func != 'function') { |
| 35999 | return identity; |
| 36000 | } |
| 36001 | // exit early for no `thisArg` or already bound by `Function#bind` |
| 36002 | if (typeof thisArg == 'undefined' || !('prototype' in func)) { |
| 36003 | return func; |
| 36004 | } |
| 36005 | var bindData = func.__bindData__; |
| 36006 | if (typeof bindData == 'undefined') { |
| 36007 | if (support.funcNames) { |
| 36008 | bindData = !func.name; |
| 36009 | } |
| 36010 | bindData = bindData || !support.funcDecomp; |
| 36011 | if (!bindData) { |
| 36012 | var source = fnToString.call(func); |
| 36013 | if (!support.funcNames) { |
| 36014 | bindData = !reFuncName.test(source); |
| 36015 | } |
| 36016 | if (!bindData) { |
| 36017 | // checks if `func` references the `this` keyword and stores the result |
| 36018 | bindData = reThis.test(source); |
| 36019 | setBindData(func, bindData); |
| 36020 | } |
| 36021 | } |
| 36022 | } |
| 36023 | // exit early if there are no `this` references or `func` is bound |
| 36024 | if (bindData === false || (bindData !== true && bindData[1] & 1)) { |
| 36025 | return func; |
| 36026 | } |
| 36027 | switch (argCount) { |
| 36028 | case 1: return function(value) { |
| 36029 | return func.call(thisArg, value); |
| 36030 | }; |
| 36031 | case 2: return function(a, b) { |
| 36032 | return func.call(thisArg, a, b); |
| 36033 | }; |
| 36034 | case 3: return function(value, index, collection) { |
| 36035 | return func.call(thisArg, value, index, collection); |
| 36036 | }; |
| 36037 | case 4: return function(accumulator, value, index, collection) { |
| 36038 | return func.call(thisArg, accumulator, value, index, collection); |
| 36039 | }; |
| 36040 | } |
| 36041 | return bind(func, thisArg); |
| 36042 | } |
| 36043 | |
| 36044 | /** |
| 36045 | * The base implementation of `createWrapper` that creates the wrapper and |
no test coverage detected