once.js 665 B

1234567891011121314151617181920212223242526
  1. var before = require('./before');
  2. /**
  3. * Creates a function that is restricted to invoking `func` once. Repeat calls
  4. * to the function return the value of the first invocation. The `func` is
  5. * invoked with the `this` binding and arguments of the created function.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 0.1.0
  10. * @category Function
  11. * @param {Function} func The function to restrict.
  12. * @returns {Function} Returns the new restricted function.
  13. * @example
  14. *
  15. * var initialize = _.once(createApplication);
  16. * initialize();
  17. * initialize();
  18. * // => `createApplication` is invoked once
  19. */
  20. function once(func) {
  21. return before(2, func);
  22. }
  23. module.exports = once;