I keep encountering this syntax, but I'm having trouble understanding what exactly it's doing:
export class SomeClass extends SomeParent { constructor(...[configuration]) { // Only reference the "configuration" line of code } }
After trying it in Node REPL, I found that there is no difference between the following two ways of writing:
function foo(...[bar]) { console.log(bar); console.log(arguments) }
...and...
function foo(bar) { console.log(bar); console.log(arguments) }
...So what does it do?
It does seem pointless. You need to ask the author of the code what their intentions are in this regard, and they should at least leave a comment.
However, there is actually a slight difference: the remaining parameters do not count towards the function's number of parameters. Therefore,
(function(bar){}).length
is1
and(function(...[bar]){}).length
is0
.