MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / restParam

Function restParam

lib/web/jshint.js:9590–9617  ·  view source on GitHub ↗

* Creates a function that invokes `func` with the `this` binding of the * created function and arguments from `start` and beyond provided as an array. * * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions

(func, start)

Source from the content-addressed store, hash-verified

9588 * // => 'hello fred, barney, & pebbles'
9589 */
9590 function restParam(func, start) {
9591 if (typeof func != 'function') {
9592 throw new TypeError(FUNC_ERROR_TEXT);
9593 }
9594 start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
9595 return function() {
9596 var args = arguments,
9597 index = -1,
9598 length = nativeMax(args.length - start, 0),
9599 rest = Array(length);
9600
9601 while (++index < length) {
9602 rest[index] = args[start + index];
9603 }
9604 switch (start) {
9605 case 0: return func.call(this, rest);
9606 case 1: return func.call(this, args[0], rest);
9607 case 2: return func.call(this, args[0], args[1], rest);
9608 }
9609 var otherArgs = Array(start + 1);
9610 index = -1;
9611 while (++index < start) {
9612 otherArgs[index] = args[index];
9613 }
9614 otherArgs[start] = rest;
9615 return func.apply(this, otherArgs);
9616 };
9617 }
9618
9619 /**
9620 * Creates a function that invokes `func` with the `this` binding of the created

Callers 3

createAssignerFunction · 0.85
createPartialFunction · 0.85
runInContextFunction · 0.85

Calls 2

applyMethod · 0.65
callMethod · 0.45

Tested by

no test coverage detected