lodash: Change invoke's category to "Arrays". [jddalton]

Former-commit-id: e8e176bacf72f721fce62630984778e4d2ff08be
This commit is contained in:
John-David Dalton
2012-04-26 01:27:50 -04:00
parent ceed641730
commit 7fa4304097
3 changed files with 118 additions and 121 deletions

View File

@@ -269,8 +269,8 @@
firstArg = /^[^,]+/.exec(args)[0],
init = options.init,
iterate = options.iterate,
arrayBranch = !(args == 'object' || iterate == 'objects'),
objectBranch = !(args == 'array' || iterate == 'arrays'),
arrayBranch = !(firstArg == 'object' || iterate == 'objects'),
objectBranch = !(firstArg == 'array' || iterate == 'arrays'),
useHas = options.useHas !== false;
// stings used to compile methods are minified during the build process
@@ -495,31 +495,6 @@
'(result[prop] || (result[prop] = [])).push(collection[index])'
});
/**
* Calls the method named by `methodName` for each value of the `collection`.
* Additional arguments will be passed to each invoked method.
*
* @static
* @memberOf _
* @category Collections
* @param {Array|Object} collection The collection to iterate over.
* @param {String} methodName The name of the method to invoke.
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with.
* @returns {Array} Returns a new array of values returned from each invoked method.
* @example
*
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
* // => [[1, 5, 7], [1, 2, 3]]
*/
var invoke = iterationFactory(mapFactoryOptions, {
'args': 'collection, methodName',
'top': 'var args = slice.call(arguments, 2), isFunc = toString.call(methodName) == funcClass',
'inLoop': {
'array': 'result[index] = (isFunc ? methodName : collection[index][methodName]).apply(collection[index], args)',
'object': 'result.push(isFunc ? methodName : collection[index][methodName]).apply(collection[index], args)'
}
});
/**
* Produces a new array of values by mapping each value in the `collection`
* through a transformation `callback`. The `callback` is bound to the `thisArg`
@@ -1123,6 +1098,28 @@
});
}
/**
* Calls the method named by `methodName` for each value of the `collection`.
* Additional arguments will be passed to each invoked method.
*
* @static
* @memberOf _
* @category Arrays
* @param {Array} array The array to iterate over.
* @param {String} methodName The name of the method to invoke.
* @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with.
* @returns {Array} Returns a new array of values returned from each invoked method.
* @example
*
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
* // => [[1, 5, 7], [1, 2, 3]]
*/
var invoke = iterationFactory(mapFactoryOptions, {
'args': 'array, methodName',
'top': 'var args = slice.call(arguments, 2), isFunc = toString.call(methodName) == funcClass',
'inLoop': 'result[index] = (isFunc ? methodName : array[index][methodName]).apply(array[index], args)'
});
/**
* Gets the last value of the `array`. Pass `n` to return the lasy `n` values
* of the `array`.