0

I keep coming across this syntax and I'm having trouble understanding exactly what it's doing:

export class SomeClass extends SomeParent {
    constructor(...[configuration]) {
        // lines of code that reference only "configuration"
    }
}

Playing around in the Node REPL I can't find a difference between:

function foo(...[bar]) { console.log(bar); console.log(arguments) }

...and...

function foo(bar) { console.log(bar); console.log(arguments) }

...so what is it for?

Chris
  • 11

1 Answers1

0

It seems pretty pointless indeed. You'll need to ask the author of the code what they intended with this, they should at least have left a comment.

However, there actually is a minuscule difference: rest parameters do not count for the function's arity. So (function(bar){}).length is 1, whereas (function(...[bar]){}).length is 0.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375