What is destructuring assignment and its uses?

后端 未结 3 757
深忆病人
深忆病人 2020-11-22 00:28

I have been reading about Destructuring assignment introduced in ES6.

What is the purpose of this syntax, why was it introduced, and what are some examples of how it

3条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 01:19

    The De-structured assignment of Javascript is probably an inspiration drawn from Perl language.

    This facilitates reuse by avoid writing getter methods or wrapper functions.

    One best example that I found very helpful in particular was on reusing functions that return more data than what is required.

    If there is a function that returns a list or an array or a json, and we are interested in only the first item of the list or array or json, then we can simply use the de-structured assignment instead of writing a new wrapper function to extract the interesting data item.

提交回复
热议问题