You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modern modularize exports="npm" -o ./`
  4. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <https://lodash.com/license>
  8. */
  9. /**
  10. * A specialized version of `baseCallback` which only supports `this` binding
  11. * and specifying the number of arguments to provide to `func`.
  12. *
  13. * @private
  14. * @param {Function} func The function to bind.
  15. * @param {*} thisArg The `this` binding of `func`.
  16. * @param {number} [argCount] The number of arguments to provide to `func`.
  17. * @returns {Function} Returns the callback.
  18. */
  19. function bindCallback(func, thisArg, argCount) {
  20. if (typeof func != 'function') {
  21. return identity;
  22. }
  23. if (thisArg === undefined) {
  24. return func;
  25. }
  26. switch (argCount) {
  27. case 1: return function(value) {
  28. return func.call(thisArg, value);
  29. };
  30. case 3: return function(value, index, collection) {
  31. return func.call(thisArg, value, index, collection);
  32. };
  33. case 4: return function(accumulator, value, index, collection) {
  34. return func.call(thisArg, accumulator, value, index, collection);
  35. };
  36. case 5: return function(value, other, key, object, source) {
  37. return func.call(thisArg, value, other, key, object, source);
  38. };
  39. }
  40. return function() {
  41. return func.apply(thisArg, arguments);
  42. };
  43. }
  44. /**
  45. * This method returns the first argument provided to it.
  46. *
  47. * @static
  48. * @memberOf _
  49. * @category Utility
  50. * @param {*} value Any value.
  51. * @returns {*} Returns `value`.
  52. * @example
  53. *
  54. * var object = { 'user': 'fred' };
  55. *
  56. * _.identity(object) === object;
  57. * // => true
  58. */
  59. function identity(value) {
  60. return value;
  61. }
  62. module.exports = bindCallback;