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用来遍历对象函数