Skip to content

before

js
_.before(n, func)

创建一个函数,使用创建函数的 this 绑定和参数调用 func,但调用次数少于 n 次。对创建的函数的后续调用将返回最后一次 func 调用的结果。

¥Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times. Subsequent calls to the created function return the result of the last func invocation.

新增于

¥Since

3.0.0

参数

¥Arguments

  1. n (数值):func 不再被调用的调用次数。

    ¥n (number): The number of calls at which func is no longer invoked.

  2. func (函数):要限制的函数。

    ¥func (Function): The function to restrict.

返回

¥Returns

(函数):返回新的受限函数。

¥(Function): Returns the new restricted function.

示例

¥Example

js
jQuery(element).on('click', _.before(5, addContactToList));
// => Allows adding up to 4 contacts to the list.

Lodash v4.17 中文网 - 粤ICP备13048890号