2 * lodash 3.6.1 (Custom Build) <https://lodash.com/>
3 * Build: `lodash modern modularize exports="npm" -o ./`
4 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
5 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
6 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
7 * Available under MIT license <https://lodash.com/license>
10 /** Used as the `TypeError` message for "Functions" methods. */
11 var FUNC_ERROR_TEXT = 'Expected a function';
13 /* Native method references for those with the same name as other `lodash` methods. */
14 var nativeMax = Math.max;
17 * Creates a function that invokes `func` with the `this` binding of the
18 * created function and arguments from `start` and beyond provided as an array.
20 * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
25 * @param {Function} func The function to apply a rest parameter to.
26 * @param {number} [start=func.length-1] The start position of the rest parameter.
27 * @returns {Function} Returns the new function.
30 * var say = _.restParam(function(what, names) {
31 * return what + ' ' + _.initial(names).join(', ') +
32 * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
35 * say('hello', 'fred', 'barney', 'pebbles');
36 * // => 'hello fred, barney, & pebbles'
38 function restParam(func, start) {
39 if (typeof func != 'function') {
40 throw new TypeError(FUNC_ERROR_TEXT);
42 start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
46 length = nativeMax(args.length - start, 0),
49 while (++index < length) {
50 rest[index] = args[start + index];
53 case 0: return func.call(this, rest);
54 case 1: return func.call(this, args[0], rest);
55 case 2: return func.call(this, args[0], args[1], rest);
57 var otherArgs = Array(start + 1);
59 while (++index < start) {
60 otherArgs[index] = args[index];
62 otherArgs[start] = rest;
63 return func.apply(this, otherArgs);
67 module.exports = restParam;