[鏈接]()### 基本用法
轉為對象以后具備 [Iterator 接口](https://blog.csdn.net/li1484155613/article/details/102171103),要么本身就具備 Iterator 接口
```
function* fibs() {
let a = 0;
let b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
let [first, second, third, fourth, fifth, sixth] = fibs();
sixth // 5
```
*****
## 對象的解構賦值
對象的解構與數組有一個重要的不同,變量必須與屬性同名,才能取到正確的值
```
let { bar, foo } = { foo: 'aaa', bar: 'bbb' };
foo // "aaa"
bar // "bbb"
let { baz } = { foo: 'aaa', bar: 'bbb' };
baz // undefined
```
三次解構賦值,分別是對`loc`、`start`、`line`三個屬性的解構賦值,只有`line`是變量,`loc`和`start`都是模式,不是變量。
```
const node = {
loc: {
start: {
line: 1,
column: 5
}
}
};
let { loc, loc: { start }, loc: { start: { line }} } = node;
line // 1
loc // Object {start: Object}
start // Object {line: 1, column: 5}
```
對象的解構賦值可以取到繼承的屬性
```
const obj1 = {};
const obj2 = { foo: 'bar' };
Object.setPrototypeOf(obj1, obj2);
const { foo } = obj1;
foo // "bar"
```
對象`obj1`的原型對象是`obj2`。`foo`屬性不是`obj1`自身的屬性,而是繼承自`obj2`的屬性,解構賦值可以取到這個屬性