Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
/**
2
* This method invokes `interceptor` and returns `value`. The interceptor is
3
* bound to `thisArg` and invoked with one argument; (value). The purpose of
4
* this method is to "tap into" a method chain in order to perform operations
5
* on intermediate results within the chain.
6
*
7
* @static
8
* @memberOf _
9
* @category Chain
10
* @param {*} value The value to provide to `interceptor`.
11
* @param {Function} interceptor The function to invoke.
12
* @param {*} [thisArg] The `this` binding of `interceptor`.
13
* @returns {*} Returns `value`.
14
* @example
15
*
16
* _([1, 2, 3])
17
* .tap(function(array) {
18
* array.pop();
19
* })
20
* .reverse()
21
* .value();
22
* // => [2, 1]
23
*/
24
function tap(value, interceptor, thisArg) {
25
interceptor.call(thisArg, value);
26
return value;
27
}
28
29
module.exports = tap;
30
31