Destructuring

simple example

let [a, b, c] = [1, 2, 3];
console.log(a);
console.log(b);
console.log(c);

incomplete destructuring

let [x, y] = [1, [2, 3]];
console.log(x);
console.log(y);

generatorFunction

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();
console.log(first);
console.log(sixth);

object

const user = {
  firstName: 'Robin',
  lastName: 'Wieruch',
};
let {firstName, lastName} = user;
console.log(firstName + ' ' + lastName);  //  Robin Wieruch

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/function*

results matching ""

    No results matching ""