It is 解构赋值 https://github.com/lukehoban/es6features#destructuring.
解构赋值语法是一个 JavaScript 表达式
使得可以从数组中解压值,或从
对象,转化为不同的变量。
示例(ES6):
var person = {firstname: 'john', lastname: 'doe'};
const firstname = person.firstname;
const lastname = person.lastname;
// same as this
const { firstname, lastname } = person;
您可以在以下位置找到更多信息:MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
编辑:对于熟悉 Python 语言的开发人员来说,与 Python 解包语法进行比较可能会很有趣。
Python2.7:
>>> _tuple = (1, 2, 3)
>>> a, b, c = _tuple
>>> print(a, b, c)
(1, 2, 3)
随着Python3的新功能,比如PEP 3132 https://www.python.org/dev/peps/pep-3132/您还可以执行以下操作:
>>> _range = range(5)
>>> a, *b, c = _range
>>> print(a, b, c)
0 [1, 2, 3] 4
添加示例是因为了解其他语言中已经类似的方法,您可以更快地掌握 JS 思想。