You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					37 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					37 lines
				
				1.1 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								var apply = require('./_apply');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* Built-in method references for those with the same name as other `lodash` methods. */
							 | 
						||
| 
								 | 
							
								var nativeMax = Math.max;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * A specialized version of `baseRest` which transforms the rest array.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @private
							 | 
						||
| 
								 | 
							
								 * @param {Function} func The function to apply a rest parameter to.
							 | 
						||
| 
								 | 
							
								 * @param {number} [start=func.length-1] The start position of the rest parameter.
							 | 
						||
| 
								 | 
							
								 * @param {Function} transform The rest array transform.
							 | 
						||
| 
								 | 
							
								 * @returns {Function} Returns the new function.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								function overRest(func, start, transform) {
							 | 
						||
| 
								 | 
							
								  start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
							 | 
						||
| 
								 | 
							
								  return function() {
							 | 
						||
| 
								 | 
							
								    var args = arguments,
							 | 
						||
| 
								 | 
							
								        index = -1,
							 | 
						||
| 
								 | 
							
								        length = nativeMax(args.length - start, 0),
							 | 
						||
| 
								 | 
							
								        array = Array(length);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    while (++index < length) {
							 | 
						||
| 
								 | 
							
								      array[index] = args[start + index];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    index = -1;
							 | 
						||
| 
								 | 
							
								    var otherArgs = Array(start + 1);
							 | 
						||
| 
								 | 
							
								    while (++index < start) {
							 | 
						||
| 
								 | 
							
								      otherArgs[index] = args[index];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    otherArgs[start] = transform(array);
							 | 
						||
| 
								 | 
							
								    return apply(func, this, otherArgs);
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = overRest;
							 |