es6.ruanyifeng.com/#docs/introes6
let arr = [1, 2, 3];
let [a, b, c] = arr;
console.log(a, b, c); // 輸出 1 2 3
複製代碼
let { foo, bar } = {foo: 'aaa', bar: 'bbb'};
console.log(foo, bar); // aaa, bbb
let {a, c} = {a: 'hello', b: 'world'};
console.log(a, c); // hello, undefined
複製代碼
// 非箭頭函數
let fn = function (x) {
return x * 2;
}
// 箭頭函數,等同於上面的函數
let fn = (x) => {
return x * 2;
}
複製代碼
當異步請求變多時,就會成爲回調地域,Promise是異步編程的一種解決方案,解決開發者對異步回調的煩惱。編程
一個 Promise 對象有三個狀態,而且狀態一旦改變,便不能再被更改成其餘狀態。數組
模板字符串,優化字符串拼接,ES5經過反斜槓''來作多行字符串,ES6用反引號'`'直接搞定。bash
// bad
const foo = 'this is a' + example;
// good
const foo = `this is a ${example}`;
複製代碼
includes() 函數用來判斷一個數組是否包含一個指定的值,若是包含則返回 true,不然返回false。異步
for···of用來遍歷數組異步編程
for···in用來遍歷對象函數