您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

throttle.js 620B

123456789101112131415161718192021222324
  1. import debounce from './debounce'
  2. import isObject from './isObject'
  3. let FUNC_ERROR_TEXT = 'Expected a function'
  4. function throttle(func, wait, options) {
  5. let leading = true,
  6. trailing = true
  7. if (typeof func != 'function') {
  8. throw new TypeError(FUNC_ERROR_TEXT)
  9. }
  10. if (isObject(options)) {
  11. leading = 'leading' in options ? !!options.leading : leading
  12. trailing = 'trailing' in options ? !!options.trailing : trailing
  13. }
  14. return debounce(func, wait, {
  15. 'leading': leading,
  16. 'maxWait': wait,
  17. 'trailing': trailing,
  18. })
  19. }
  20. export default throttle