Skip to content

once

js
_.once(func)

创建一个限制为调用 func 一次的函数。重复调用该函数将返回第一次调用的值。func 使用创建的函数的 this 绑定和参数调用。

¥Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation. The func is invoked with the this binding and arguments of the created function.

新增于

¥Since

0.1.0

参数

¥Arguments

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

    ¥func (Function): The function to restrict.

返回

¥Returns

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

¥(Function): Returns the new restricted function.

示例

¥Example

js
var initialize = _.once(createApplication);
initialize();
initialize();
// => `createApplication` is invoked once

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