Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 789 Bytes

no-arguments.md

File metadata and controls

28 lines (19 loc) · 789 Bytes

Forbid the use of arguments

arguments is a special variable made implicitly available in functions, which is an object containing the arguments passed to the function call. This is often used to allow any number of parameters to be passed to a function.

Functional programming works better with known and explicit parameters. Also, having an undefined number of parameters does not work well with currying.

Fail

function sum() {
  const numbers = Array.prototype.slice.call(arguments);
  return numbers.reduce((a, b) => a + b);
}

sum(1, 2, 3);

Pass

function sum(numbers) {
  return numbers.reduce((a, b) => a + b);
}

sum([1, 2, 3]);

var args = node.arguments;