In lodash there is the _.chain method that can be used to create what are called explicit method chain sequences. In addition there is also the main function of lodash, that when called can be used to create implicit method chain sequences that work in a similar fashion to what you may all ready be familiar with when it comes to chaining vanilla js native methods. There is yet even another option that can be deployed as a way to create a chain of sorts that is the lodash flow method that works by passing an array of functions to use. It may be best actually to use a function such as flow over that of the lodash chain method for various reasons that one will get into when making custom lodash builds.
Although this is a lodash post I will be covering chaining with, and without lodash in this post in an effort to cover chaining in general.
1 - lodash chain basics, and what to know first
1.1 - Explicit Chaining with _.chain
When passing a value to _.chain the returned result is a wrapped value ready for explicit chaining. Functions that return arrays, collections, functions, and values of any kind can then be chained together. However once done in order to unwrap the chain the _.value method must be called.
1.2 - Implicit Chaining with the main lodash method _()
Many of the methods in lodash are properties of the _ variable that is added to the global name space when using lodash. However the _ variable is a function rather than just a plain old object, and as such it can be called and passed a value. When using the main lodash method in place of _.chain that is what is called Implicit chaining. It is more is less the same as the explicit chaining only using a method like _.sum will result in unwrapping the wrapped value, so the _.value method does not need to be used in such a case.
2 - Chaining with Native array methods
When working with an native array methods as long as what is returned is also an array then I can continuing calling additional array methods on the array. If I am not using lodash then I am limited to what there is to work with in the Array prototype, as well as the prototypes of other built in classes depending on what is returned.
For example there is no native equivalent of _.sum, however it is not to hard to quickly sum an array using the native Array.reduce method.
3 - Conclusion