1 | var apply = require('./_apply');
|
2 |
|
3 |
|
4 | var nativeMax = Math.max;
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function overRest(func, start, transform) {
|
16 | start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
|
17 | return function() {
|
18 | var args = arguments,
|
19 | index = -1,
|
20 | length = nativeMax(args.length - start, 0),
|
21 | array = Array(length);
|
22 |
|
23 | while (++index < length) {
|
24 | array[index] = args[start + index];
|
25 | }
|
26 | index = -1;
|
27 | var otherArgs = Array(start + 1);
|
28 | while (++index < start) {
|
29 | otherArgs[index] = args[index];
|
30 | }
|
31 | otherArgs[start] = transform(array);
|
32 | return apply(func, this, otherArgs);
|
33 | };
|
34 | }
|
35 |
|
36 | module.exports = overRest;
|