defer.js 699 B

12345678910111213141516171819202122232425
  1. var baseDelay = require('../internal/baseDelay'),
  2. restParam = require('./restParam');
  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. * @category Function
  10. * @param {Function} func The function to defer.
  11. * @param {...*} [args] The arguments to invoke the function with.
  12. * @returns {number} Returns the timer id.
  13. * @example
  14. *
  15. * _.defer(function(text) {
  16. * console.log(text);
  17. * }, 'deferred');
  18. * // logs 'deferred' after one or more milliseconds
  19. */
  20. var defer = restParam(function(func, args) {
  21. return baseDelay(func, 1, args);
  22. });
  23. module.exports = defer;