Xiaobai's question about loadsh _ .after

the official api example is too concise
var saves = ["profile"," settings"];

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

_ .forEach (saves, function (type) {
asyncSave ({"type": type," complete": done});
});
doesn"t quite understand.... Ask the Great God to explain-sharp-sharp-sharp topic description

Apr.30,2022

var done = _.after(n, func)
this method creates a function that invokes func once it's called n or more times.

means that done this function executes the func function when it is called n times or more.


first look at API, which is roughly understood to return a function. After waiting for n times of execution, execute func

function after(n, func) {
      if (typeof func != 'function') {
        throw new TypeError(FUNC_ERROR_TEXT);
      }
      n = toInteger(n);
      return function() {
        if (--n < 1) {
          return func.apply(this, arguments);
        }
      };
    }
Menu