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);
        }
      };
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36a38-2c010.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36a38-2c010.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?