## throttle
+ [link](./throttle "Link to this entry.")
+ [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L9172 "View in source.")
+ [npm](https://www.npmjs.com/package/lodash.throttle "See the npm package.")
```
_.throttle(func, [wait=0], [options])
```
创建一个节流函数,在 `wait` 秒内最多执行 `func` 一次的函数。 该函数提供一个 cancel 方法取消延迟的函数调用以及 flush 方法立即调用。 可以提供一个 options 对象决定如何调用 func 方法, options.leading 与|或 options.trailing 决定 `wait` 前后如何触发。 func 会传入最后一次传入的参数给这个函数。 随后调用的函数返回是最后一次 func 调用的结果。
**注意:** 如果 leading 和 trailing 都设定为 true。 则 func 允许 trailing 方式调用的条件为: 在 wait 期间多次调用。
查看 [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation) 了解 `_.throttle` 与 `_.debounce` 的区别
### 参数
1. func (Function)
要节流的函数
2. [wait=0] (number)
需要节流的毫秒
3. [options] (Object)
选项对象
4. [options.leading=true] (boolean)
指定调用在节流开始前
5. [options.trailing=true] (boolean)
指定调用在节流结束后
### 返回值 (Function)
返回节流的函数
### 示例
```
// 避免在滚动时过分的更新定位
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
// 点击后就调用 `renewToken`,但5分钟内超过1次。
var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
jQuery(element).on('click', throttled);
// 取消一个 trailing 的节流调用
jQuery(window).on('popstate', throttled.cancel);
```
- 主页
- 入门指南
- 下载
- 引入
- 模块格式
- 深入了解
- 兼容性
- 版本定制
- Array
- chunk
- compact
- concat
- difference
- differenceBy
- differenceWith
- drop
- dropRight
- dropRightWhile
- dropWhile
- fill
- findIndex
- findLastIndex
- flatten
- flattenDeep
- flattenDepth
- fromPairs
- head first
- indexOf
- initial
- intersection
- intersectionBy
- intersectionWith
- join
- last
- lastIndexOf
- prototype.reverse
- pull
- pullAll
- pullAllBy
- pullAt
- remove
- slice
- sortedIndex
- sortedIndexBy
- sortedIndexOf
- sortedLastIndex
- sortedLastIndexBy
- sortedLastIndexOf
- sortedUniq
- sortedUniqBy
- tail
- take
- takeRight
- takeRightWhile
- takeWhile
- union
- unionBy
- unionWith
- uniq
- uniqBy
- uniqWith
- unzip
- unzipWith
- without
- xor
- xorBy
- xorWith
- zip
- zipObject
- zipObjectDeep
- zipWith
- Collection
- countBy
- every
- filter
- find
- findLast
- flatMap
- forEach each
- forEachRight eachRight
- groupBy
- includes
- invokeMap
- keyBy
- map
- orderBy
- partition
- reduce
- reduceRight
- reject
- sample
- sampleSize
- shuffle
- size
- some
- sortBy
- Date
- now
- Function
- after
- ary
- before
- bind
- bindKey
- curry
- curryRight
- debounce
- defer
- delay
- flip
- memoize
- negate
- once
- overArgs
- partial
- partialRight
- rearg
- rest
- spread
- throttle
- unary
- wrap
- Lang
- castArray
- clone
- cloneDeep
- cloneDeepWith
- cloneWith
- eq
- gt
- gte
- isArguments
- isArray
- isArrayBuffer
- isArrayLike
- isArrayLikeObject
- isBoolean
- isBuffer
- isDate
- isElement
- isEmpty
- isEqual
- isEqualWith
- isError
- isFinite
- isFunction
- isInteger
- isLength
- isMap
- isMatch
- isMatchWith
- isNaN
- isNative
- isNil
- isNull
- isNumber
- isObject
- isObjectLike
- isPlainObject
- isRegExp
- isSafeInteger
- isSet
- isString
- isSymbol
- isTypedArray
- isUndefined
- isWeakMap
- isWeakSet
- lt
- lte
- toArray
- toInteger
- toLength
- toNumber
- toPlainObject
- toSafeInteger
- toString
- Math
- add
- ceil
- floor
- max
- maxBy
- mean
- min
- minBy
- round
- subtract
- sum
- sumBy
- Methods
- templateSettings.imports._
- Number
- clamp
- inRange
- random
- Object
- assign
- assignIn extend
- assignInWith extendWith
- assignWith
- at
- create
- defaults
- defaultsDeep
- findKey
- findLastKey
- forIn
- forInRight
- forOwn
- forOwnRight
- functions
- functionsIn
- get
- has
- hasIn
- invert
- invertBy
- invoke
- keys
- keysIn
- mapKeys
- mapValues
- merge
- mergeWith
- omit
- omitBy
- pick
- pickBy
- result
- set
- setWith
- toPairs
- toPairsIn
- transform
- unset
- values
- valuesIn
- Properties
- templateSettings
- templateSettings.escape
- templateSettings.evaluate
- templateSettings.imports
- templateSettings.interpolate
- templateSettings.variable
- VERSION
- Seq
- _
- chain
- prototype.at
- prototype.chain
- prototype.commit
- prototype.next
- prototype.plant
- prototype.Symbol.iterator
- prototype.value run, toJSON, valueOf
- tap
- thru
- wrapperFlatMap
- String
- camelCase
- capitalize
- deburr
- endsWith
- escape
- escapeRegExp
- kebabCase
- lowerCase
- lowerFirst
- pad
- padEnd
- padStart
- parseInt
- repeat
- replace
- snakeCase
- split
- startCase
- startsWith
- template
- toLower
- toUpper
- trim
- trimEnd
- trimStart
- truncate
- unescape
- upperCase
- upperFirst
- words
- Util
- attempt
- bindAll
- cond
- conforms
- constant
- flow
- flowRight
- identity
- iteratee
- matches
- matchesProperty
- method
- methodOf
- mixin
- noConflict
- noop
- nthArg
- over
- overEvery
- overSome
- property
- propertyOf
- range
- rangeRight
- runInContext
- times
- toPath
- uniqueId