From a great guide :
Chaining
[...]
Calling the chain will cause all calls to future methods to return wrapped objects. When you finish the calculation, use the value to get the final value.
So the chain in the Underscore context is the same as the chain elsewhere, except that you are binding Underscore methods on a wrapped object. You start by calling _.chain to get your wrapper:
_(obj).chain()
then you call the Underscore methods when returning _.chain , and they also return wrapped objects:
_(obj).chain() .filter(function(x) { ... }) .map(function(x) { ... }) ...
and finally you call _.value to expand the wrapper chain:
var result = _(obj).chain() .filter(function(x) { ... }) .map(function(x) { ... }) ... .value();
Return to _.tap . All tap does this :
_.tap = function(obj, interceptor) { interceptor(obj); return obj; };
so that it calls the passed function, interceptor , when it repeats and returns what is being executed, without any action. _.tap same as:
.map(function(x) { f(x); return x })
but it makes your intention clear. In fact, _.tap allows _.tap to look into data passing through a chain of methods without changing that data.
mu is too short
source share