ES6 new features Summary and Introduction - Statement of expression

ES6 standard entry Ruan Yifeng is relatively long, the recent discovery rookie tutorial ES6 tutorial written yet (xie) not (de) wrong (duan), ready to read.

A, let the const

1. let

  • The valid block
  • Can not be repeated statement
  • There is no variable lift

2. const

  • Declare a constant
  • For complex types, variables at the memory address actually stores a pointer to the actual data, we can only guarantee const pointer is fixed, as the data structure pointer constant change can not control.

Second, deconstruction assignment

1. The array model deconstruction (the Array)

let [a, b, c] = [1, 2, 3];
// a = 1
// b = 2
// c = 3
复制代码

2. The object model deconstruction (Array)

let { foo, bar } = { foo: 'aaa', bar: 'bbb' };
// foo = 'aaa'
// bar = 'bbb'
复制代码

Third, expand operator (remainder operator)

1. Expand the grammar

The expansion arrays and objects for each element therein.

let arr1 = [0, 1, 2];
let arr2 = [3, 4, 5];
let arr3 = [...arr1, ...arr2]
//arr3 = [ 0, 1, 2, 3, 4, 5]

let z = { a: 3, b: 4 };
let n = { ...z };
n // { a: 3, b: 4 }
复制代码
2. The remaining operators

The remaining parameter syntax allows us to a variable number of arguments is represented as an array.

function(a, b, ...rest) {
  // ...
}
复制代码

The difference between the parameter and the remaining three main arguments object:

  1. The remaining parameters include only those parameter corresponding to no argument, the arguments object contains all the arguments passed to the function.
  2. arguments object is not a true array, while the remaining parameters are the real array.
  3. There are additional arguments object attributes (attributes such as callee).

Reproduced in: https: //juejin.im/post/5cf629ab6fb9a07f0219ecbb

Guess you like

Origin blog.csdn.net/weixin_34050005/article/details/91473219