baseCallback.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. var baseMatches = require('./baseMatches'),
  2. baseMatchesProperty = require('./baseMatchesProperty'),
  3. bindCallback = require('./bindCallback'),
  4. identity = require('../utility/identity'),
  5. property = require('../utility/property');
  6. /**
  7. * The base implementation of `_.callback` which supports specifying the
  8. * number of arguments to provide to `func`.
  9. *
  10. * @private
  11. * @param {*} [func=_.identity] The value to convert to a callback.
  12. * @param {*} [thisArg] The `this` binding of `func`.
  13. * @param {number} [argCount] The number of arguments to provide to `func`.
  14. * @returns {Function} Returns the callback.
  15. */
  16. function baseCallback(func, thisArg, argCount) {
  17. var type = typeof func;
  18. if (type == 'function') {
  19. return thisArg === undefined
  20. ? func
  21. : bindCallback(func, thisArg, argCount);
  22. }
  23. if (func == null) {
  24. return identity;
  25. }
  26. if (type == 'object') {
  27. return baseMatches(func);
  28. }
  29. return thisArg === undefined
  30. ? property(func)
  31. : baseMatchesProperty(func, thisArg);
  32. }
  33. module.exports = baseCallback;