The lodash constant method is a method that will create a function that will return a given static constant value each time it is called. On the surface lodash constant might seem pointless, but there are some situations in which I might actually want a method like this. Say for example I have a function that expects a function as one of its arguments, I can not just pass a static value to it, so instead I would need to pass a function that will return that static value.
There are a number of built in methods that will return a static value each time it is called to begin with in lodash, but the lodash constant method is the built in way to create my one such methods. It is also true that it is not so hard to just do the same things without the use of lodash, so I will be looking at some plain old vanilla javaScirpt alternatives to using the lodash constant method also here.
So the basic idea here is that I call the lodash constant method and a new function will be returned, when doing so I pass the lodash constant method a static value that I want the resulting function to return each time it is called. So I can call the lodash constant method and pass a true boolean value to it as the first argument. The result that is returned by the lodash constant method is then a new function that will return true each time it is called.
So one thing that comes to mind with this is to have a way to quickly cerate a noop function, or a no operation function. I guess I could use something like the lodash constant method and pass undefined for the value, or use the lodash noop method. However why should I bother with any of those when I can just use arrow functions, or expressions, and reduce the need for lodash?
So the lodash constant method is not one of those must have methods in lodash, and I think that will just become even more the case as time goes on. When it comes to methods that I might actually use in a project there are only a hand full that come to mind actually that I think I would bother with and this is not one of them.