constant.js 444 B

1234567891011121314151617181920212223
  1. /**
  2. * Creates a function that returns `value`.
  3. *
  4. * @static
  5. * @memberOf _
  6. * @category Utility
  7. * @param {*} value The value to return from the new function.
  8. * @returns {Function} Returns the new function.
  9. * @example
  10. *
  11. * var object = { 'user': 'fred' };
  12. * var getter = _.constant(object);
  13. *
  14. * getter() === object;
  15. * // => true
  16. */
  17. function constant(value) {
  18. return function() {
  19. return value;
  20. };
  21. }
  22. module.exports = constant;