ES6 相关用法

# 1、模板字符串

用于拼接字符串 ${}

let a = 'Hello'
console.log(`${a} World`)
console.log(a + ' World')

# 2、Set,Map

const grade = new Map()
  .set("A", "90-100")
  .set("B", "80-89")
  .set("C", "70-79")
  .set("D", "60-69")
  .set("E", "0-59");

function getGrade(score) {
  return grade.get(score) || [];
}
console.log(getGrade("B"));

// 数组去重
[...new Set(arr)];

# 3、Async

async function getList() {
  await getTableList().then();
}

# 4、Object.assign()

用于将所有可枚举属性的值从一个或多个源对象 source 复制到目标对象,返回目标对象target,属于浅拷贝

const target = { a: 1, b: 2 };
const source = { b: 3, c: 4 };
const res = Object.assign(target, source); // {a:1,b:4,c:4} 同名属性替换
target; // {a:1,b:4,c:4}

# 5、解构赋值

将数组中的值或对象的属性取出,赋值给其他变量

let a, b, rest;
[a, b] = [10, 20];
console.log(a, b); // 10,20

[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(rest); // [30,40,50]

const user = {
  id: 42,
  name: "11",
};
const { id, name } = user;
console.log(id); // 42
console.log(name); // '11'