这个js语法叫什么?

What is this js syntax called?

本文关键字:什么 语法 js 这个      更新时间:2023-09-26

我不确定是否有一个特定的名称为这种方式拉对象属性到自己的变量?如果有名字,有人知道吗?

var object = {
  something: 'a string',
  another: 'another string',
}
var { something, another } = object;

这叫做对象解构

对象解构,详细阅读:

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

很多新的语法并没有在所有的js引擎中完全实现,所以在使用它的时候要小心!

如果您想了解更多,请查看本教程:

https://www.eventbrite.com/engineering/learning-es6-destructuring/