_baseDelay.js 672 B

12345678910111213141516171819202122
  1. /** Error message constants. */
  2. var FUNC_ERROR_TEXT = 'Expected a function';
  3. /**
  4. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  5. * to provide to `func`.
  6. *
  7. * @private
  8. * @param {Function} func The function to delay.
  9. * @param {number} wait The number of milliseconds to delay invocation.
  10. * @param {Array} args The arguments to provide to `func`.
  11. * @returns {number|Object} Returns the timer id or timeout object.
  12. */
  13. function baseDelay(func, wait, args) {
  14. if (typeof func != 'function') {
  15. throw new TypeError(FUNC_ERROR_TEXT);
  16. }
  17. return setTimeout(function() { func.apply(undefined, args); }, wait);
  18. }
  19. module.exports = baseDelay;