Why are there advantages to using both spread operator and destructuring assignment in function parameters?
P粉775723722
P粉775723722 2023-08-16 16:27:57
0
1
382

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?

P粉775723722
P粉775723722

reply all (1)
P粉670107661

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){}).lengthis1and(function(...[bar]){}).lengthis0.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!