[Fixed] What is the meaning of "…args" (three dots) in a function definition?


It was really confusing for me to read this syntax in Javascript:

.put((...args) => controller.update(...args))
.get((...args) => controller.findById(...args));

What does …args mean?


With respect to (...args) =>, ...args is a rest parameter. It always has to be the last entry in the parameter list and it will be assigned an array that contains all arguments that haven’t been assigned to previous parameters.

It’s basically the replacement for the arguments object. Instead of writing

function max() {
  var values = Array.prototype.slice.call(arguments, 0);
  // ...

you can write

function max(...value) {
  // ...

Also, since arrow functions don’t have an arguments object, this is the only way to create variadic (arrow) functions.

As controller.update(...args), see What is the meaning of "foo(…arg)" (three dots in a function call)? .

Leave a Reply

(*) Required, Your email will not be published