Lodash _.defer() Method
Last Updated :
31 Oct, 2023
Lodash _.defer() method in lodash is used to defer the calling of the func parameter until the recent call stack is cleared. Moreover, any further arguments are provided to the function parameter of this method when it is called.
Syntax:
_.defer(func, [args]);
Parameters:
- func: It is the function that is to be deferred.
- [args]: It is the arguments with which the function is being called.
Return Value:
This method returns the timer id.
Example 1: In this example, we are using the lodash _.defer() method because of this ‘Content’ is printing first.
Javascript
const _ = require( 'lodash' );
_.defer( function (content) {
console.log(content);
}, 'GeeksforGeeks!' );
console.log( 'Content:' );
|
Output:
Content:
GeeksforGeeks!
Example 2: In this example, we are using the lodash _.defer() method because of this ‘Integers are as follows:’ is printing first.
Javascript
const _ = require( 'lodash' );
let func = number => {
console.log(number);
};
for (let i = 1; i <= 5; i++) {
_.defer(func, i);
}
console.log( 'Integers are as follows:' );
|
Output:
Integers are as follows:
1
2
3
4
5
Reference: https://lodash.com/docs/4.17.15#defer
Share your thoughts in the comments
Please Login to comment...