source: frontend/node_modules/underscore/amd/restArguments.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
Line 
1define(function () {
2
3 // Some functions take a variable number of arguments, or a few expected
4 // arguments at the beginning and then a variable number of values to operate
5 // on. This helper accumulates all remaining arguments past the function’s
6 // argument length (or an explicit `startIndex`), into an array that becomes
7 // the last argument. Similar to ES6’s "rest parameter".
8 function restArguments(func, startIndex) {
9 startIndex = startIndex == null ? func.length - 1 : +startIndex;
10 return function() {
11 var length = Math.max(arguments.length - startIndex, 0),
12 rest = Array(length),
13 index = 0;
14 for (; index < length; index++) {
15 rest[index] = arguments[index + startIndex];
16 }
17 switch (startIndex) {
18 case 0: return func.call(this, rest);
19 case 1: return func.call(this, arguments[0], rest);
20 case 2: return func.call(this, arguments[0], arguments[1], rest);
21 }
22 var args = Array(startIndex + 1);
23 for (index = 0; index < startIndex; index++) {
24 args[index] = arguments[index];
25 }
26 args[startIndex] = rest;
27 return func.apply(this, args);
28 };
29 }
30
31 return restArguments;
32
33});
Note: See TracBrowser for help on using the repository browser.