Skip to content

after

js
_.after(n, func)

选项对象。此方法创建一个函数,一旦调用 n 或更多次,该函数就会调用 func

¥The opposite of _.before; this method creates a function that invokes func once it's called n or more times.

新增于

¥Since

0.1.0

参数

¥Arguments

  1. n (数值):func 被调用之前的调用次数。

    ¥n (number): The number of calls before func is invoked.

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

    ¥func (Function): The function to restrict.

返回

¥Returns

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

¥(Function): Returns the new restricted function.

示例

¥Example

js
var saves = ['profile', 'settings'];

var done = _.after(saves.length, function() {
  console.log('done saving!');
});

_.forEach(saves, function(type) {
  asyncSave({ 'type': type, 'complete': done });
});
// => Logs 'done saving!' after the two async saves have completed.

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