defer.js 693 B

123456789101112131415161718192021222324252627
  1. var baseDelay = require('./_baseDelay'),
  2. baseRest = require('./_baseRest');
  3. /**
  4. * Defers invoking the `func` until the current call stack has cleared. Any
  5. * additional arguments are provided to `func` when it's invoked.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 0.1.0
  10. * @category Function
  11. * @param {Function} func The function to defer.
  12. * @param {...*} [args] The arguments to invoke `func` with.
  13. * @returns {number} Returns the timer id.
  14. * @example
  15. *
  16. * _.defer(function(text) {
  17. * console.log(text);
  18. * }, 'deferred');
  19. * // => Logs 'deferred' after one millisecond.
  20. */
  21. var defer = baseRest(function(func, args) {
  22. return baseDelay(func, 1, args);
  23. });
  24. module.exports = defer;