mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Bump to v4.11.0.
This commit is contained in:
18
nthArg.js
18
nthArg.js
@@ -1,7 +1,8 @@
|
||||
define(['./toInteger'], function(toInteger) {
|
||||
define(['./_baseNth', './rest', './toInteger'], function(baseNth, rest, toInteger) {
|
||||
|
||||
/**
|
||||
* Creates a function that returns its nth argument.
|
||||
* Creates a function that returns its nth argument. If `n` is negative,
|
||||
* the nth argument from the end is returned.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -12,15 +13,18 @@ define(['./toInteger'], function(toInteger) {
|
||||
* @example
|
||||
*
|
||||
* var func = _.nthArg(1);
|
||||
*
|
||||
* func('a', 'b', 'c');
|
||||
* func('a', 'b', 'c', 'd');
|
||||
* // => 'b'
|
||||
*
|
||||
* var func = _.nthArg(-2);
|
||||
* func('a', 'b', 'c', 'd');
|
||||
* // => 'c'
|
||||
*/
|
||||
function nthArg(n) {
|
||||
n = toInteger(n);
|
||||
return function() {
|
||||
return arguments[n];
|
||||
};
|
||||
return rest(function(args) {
|
||||
return baseNth(args, n);
|
||||
});
|
||||
}
|
||||
|
||||
return nthArg;
|
||||
|
||||
Reference in New Issue
Block a user