Files
lodash/internal/baseCallback.js
John-David Dalton 9b7c4d6761 Bump to v3.0.0.
2015-05-19 22:25:55 -07:00

31 lines
1.1 KiB
JavaScript

define(['./baseMatches', './baseProperty', './baseToString', './bindCallback', '../utility/identity', './isBindable'], function(baseMatches, baseProperty, baseToString, bindCallback, identity, isBindable) {
/**
* The base implementation of `_.callback` which supports specifying the
* number of arguments to provide to `func`.
*
* @private
* @param {*} [func=_.identity] The value to convert to a callback.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {number} [argCount] The number of arguments to provide to `func`.
* @returns {Function} Returns the callback.
*/
function baseCallback(func, thisArg, argCount) {
var type = typeof func;
if (type == 'function') {
return (typeof thisArg != 'undefined' && isBindable(func))
? bindCallback(func, thisArg, argCount)
: func;
}
if (func == null) {
return identity;
}
// Handle "_.property" and "_.matches" style callback shorthands.
return type == 'object'
? baseMatches(func, !argCount)
: baseProperty(argCount ? baseToString(func) : func);
}
return baseCallback;
});