For this basic debounce method example I just called it and pass the function that I want debounced, and a time in milliseconds as a second argument. Once that is done a debounced function will then be returned, once called the function will be invoked once the given about of time passes.
A _.debounce method comes with a flush method that can be used to call the method at once right alway. This flush method can be called off from and object that is returned when calling lodash denounce.
So then for a basic setTimeout method example I just call the setTimeout method and pass the function that I want called after a time out value in milliseconds. That is it then as the return value is not a function but a number that is used as an id for this that can be used to cancel the calling of the function later on with a method known as clearTimeout.
I can then make a loop example of the setTimeout method in a similar way of that of the loop example using lodash denounce. The difference is that I pass a reference to the function that I pass to setTeout rather than calling the function that is returned because once again it is not a function that is returned by setTimeout.
The setInterval method is another option that can be used to delay the calling of a function, but it will not just delay the function, but rather call it over and over again.
Now for at least one example of delaying a function in a nodejs environment.
Here I have an example where I am using the process global in nodejs to get argument values to set the delay, as well as the number of times to call a function.
The _.debounce method in lodash can be useful when making some methods that need to do something every once in a while, but also need to be check right away in some situations. So then the debounce method is very similar to that of native methods like setTimeout only with a few key differences such as the fact that the return value is a function rather than an id that can be used with clearTimeout, and that the delay will start when the returned function is called rater than right away.