Why are the rest parameters in JavaScript called so? [closed]
Asked Answered
T

2

9

Why are rest parameters in JavaScript called so?

Teetotal answered 25/4, 2013 at 15:50 Comment(3)
this is along the lines of "why 42" It doesn't really impact the usage to understand the name. And this isn't really the type of question to be asked here. Ask someone apart of the board dreaming up EcmaScript 6 and use this site for specific programming problems.Bremen
This name comes from the following definition for the word rest: rest: the part that is left or remains; remainder.Environ
To understand why something is named so can help more greatly understand, remember, and appreciate the term's meaning. Etymology is constructive to learning.Motto
E
7

They are called rest parameters because they capture the rest of the parameters when the function was invoked.

function multiply(multiplier, ...theArgs) {
  return theArgs.map(function (element) {
    return multiplier * element;
  });
}

Example from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/rest_parameters#Browser_compatibility

...theArgs captures parameters 2+. In other words, multiplier is the first parameter and theArgs is the rest.

Erythrocytometer answered 25/4, 2013 at 15:53 Comment(0)
A
6

The word "rest" is used there to mean a container for the rest of the argument values, of which there may be any number.

It's historical usage possibly starting with Lisp Machine Lisp, definitely documented in the 1981 third edition of the Lisp Machine Manual. There were no "rest parameters" by that behavior or that name in Maclisp or Interlisp, both in 1974. Rest parameters in Common Lisp at present have the same syntax as they had in the Lisp Machine Manual. http://www.lispworks.com/documentation/HyperSpec/Body/03_dac.htm

The phrase "rest parameters" is first introduced in relation to ECMAScript in the 2012-07-12 ECMAScript 6 draft. It seems clear that the phrase there is to be understood as common parlance previously established by Lisp. If it really matters, I suppose we could ask the secretary of ECMA Technical Committee 39, Dr. Istvan Sebestyen, whose address is his first name at ecma-international.org, whether anyone would be willing to say that in so many words.

Antirachitic answered 25/4, 2013 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.