Term: destructuring assignment (deconstruct assignment)

Source: Internet
Author: User

Term: destructuring assignment (deconstruct assignment)
This is a new term introduced by JavaScript 1.7. As for the purpose, people who have used programming scripts such as MATLAB and Lua are no longer familiar with it.

VaR A = 1;
VaR B = 3;

[A, B] = [B, a];

In other words, multiple copies are written in one row. The main purpose is to return multiple return values, because such scripts neither have pointers nor reference parameters. Of course, it can also be used to exchange the value of a variable (as shown in the preceding example) and rotate the value of a variable sequence cyclically.

Javascript gave it such a strange name, probably because it uses its original array form. Assign an array to another array, which is a reference value. However, if the left side is a right value constant, the value cannot be assigned. Therefore, the semantics is changed to assign the value of each element to the corresponding element on the left. Therefore, it is called deconstruct value assignment, that is, the structure of the array.

Even more, destructuring looks familiar, like the destructor of C ++. Since destructor is translated into an analysis structure, why should destructure be translated into deconstruct? Check the professional dictionary and you will find that destruct and destructure are different. Destruct is destructive, crushing, and destructure is deconstruct. Obviously, destructor is the acronyms of destruct. The question is why destructor translates it into a destructor, rather than destroying or destroying a function. There is a separate and scattered interpretation of the word analysis, that is, the analysis of the split. There is also some truth in this thinking, and sharing a word structure with the constructor makes it easy to link the constructor with the constructor.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.