react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / function / restParam.js
80742 views/** Used as the `TypeError` message for "Functions" methods. */1var FUNC_ERROR_TEXT = 'Expected a function';23/* Native method references for those with the same name as other `lodash` methods. */4var nativeMax = Math.max;56/**7* Creates a function that invokes `func` with the `this` binding of the8* created function and arguments from `start` and beyond provided as an array.9*10* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).11*12* @static13* @memberOf _14* @category Function15* @param {Function} func The function to apply a rest parameter to.16* @param {number} [start=func.length-1] The start position of the rest parameter.17* @returns {Function} Returns the new function.18* @example19*20* var say = _.restParam(function(what, names) {21* return what + ' ' + _.initial(names).join(', ') +22* (_.size(names) > 1 ? ', & ' : '') + _.last(names);23* });24*25* say('hello', 'fred', 'barney', 'pebbles');26* // => 'hello fred, barney, & pebbles'27*/28function restParam(func, start) {29if (typeof func != 'function') {30throw new TypeError(FUNC_ERROR_TEXT);31}32start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);33return function() {34var args = arguments,35index = -1,36length = nativeMax(args.length - start, 0),37rest = Array(length);3839while (++index < length) {40rest[index] = args[start + index];41}42switch (start) {43case 0: return func.call(this, rest);44case 1: return func.call(this, args[0], rest);45case 2: return func.call(this, args[0], args[1], rest);46}47var otherArgs = Array(start + 1);48index = -1;49while (++index < start) {50otherArgs[index] = args[index];51}52otherArgs[start] = rest;53return func.apply(this, otherArgs);54};55}5657module.exports = restParam;585960