Add thisArg to _.tap.

This commit is contained in:
John-David Dalton
2013-12-16 02:34:20 -08:00
parent 6845a52e92
commit 172cc1ffea
6 changed files with 48 additions and 29 deletions

17
dist/lodash.compat.js vendored
View File

@@ -2955,7 +2955,7 @@
* per iteration. If a property name or object is provided it will be used
* to create a "_.pluck" or "_.where" style callback, respectively.
* @param {*} [thisArg] The `this` binding of `callback`.
* @returns {Array} Returns a new object with values of the results of each `callback` execution.
* @returns {Object} Returns a new object with values of the results of each `callback` execution.
* @example
*
* _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; });
@@ -4190,7 +4190,7 @@
* @param {number} [n] The number of elements to sample.
* @param- {Object} [guard] Allows working with functions like `_.map`
* without using their `index` arguments as `n`.
* @returns {Array} Returns the random sample(s) of `collection`.
* @returns {*} Returns the random sample(s) of `collection`.
* @example
*
* _.sample([1, 2, 3, 4]);
@@ -6825,16 +6825,17 @@
}
/**
* Invokes `interceptor` with the `value` as the first argument and then
* returns `value`. The purpose of this method is to "tap into" a method
* chain in order to perform operations on intermediate results within
* the chain.
* This method invokes `interceptor` and returns `value`. The interceptor is
* bound to `thisArg` and invoked with one argument; (value). The purpose of
* this method is to "tap into" a method chain in order to perform operations
* on intermediate results within the chain.
*
* @static
* @memberOf _
* @category Chaining
* @param {*} value The value to provide to `interceptor`.
* @param {Function} interceptor The function to invoke.
* @param {*} [thisArg] The `this` binding of `interceptor`.
* @returns {*} Returns `value`.
* @example
*
@@ -6844,8 +6845,8 @@
* .value();
* // => [3, 2, 1]
*/
function tap(value, interceptor) {
interceptor(value);
function tap(value, interceptor, thisArg) {
interceptor.call(thisArg, value);
return value;
}