> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/function/before.md).

# \_.before

**语法：**

```javascript
_.before(n, func)
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L10042)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.before)

**描述：**

创建一个调用`func`的函数，通过`this`绑定和创建函数的参数调用`func`，调用次数不超过`n`次。 之后再调用这个函数，将返回一次最后调用`func`的结果。

**开始版本：**&#x33;.0.0

**参数：**

* `n (number)`: 超过多少次不再调用func（限制调用func 的次数）。
* `func (Function)`: 限制执行的函数。

**返回值：**

* `(Function)`: 返回新的限定函数。

**例子：**

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