Lodash _.after() method is opposite of Lodash _.before() method. This method creates a function that invokes function once it’s called n or more times.
Syntax:
_.after(n, func);Parameters:
- n: This parameter holds the number n, which defines the number of calls before func is invoked.
- func: This parameter holds the function that will invoked.
Return Value:
- This method returns the new restricted function.
Example 1: In this example, we try to invoke the function 3 times but it will invoke 3rd time only.
// Requiring the lodash library
const _ = require("lodash");
// Applying _.after() method
let gfg = _.after(3, function () {
console.log('Saved');
});
gfg(); // Print nothing
gfg(); // Print nothing
gfg(); // Print Saved
Output:
SavedExample 2: In this example, we try to invoke the function 2 times but it will in invoke 2nd times only.
// Requiring the lodash library
const _ = require("lodash");
// Applying _.after() method
let gfg = _.after(2, function () {
console.log('Successful');
});
gfg(); // Print nothing
gfg(); // Print Successful
Output:
Successful