markdown

# 目录

  • ES7 (ES2016)

    • Array.prototype.includes()
    • 指数操作符(**)
  • ES8 (ES2017)

    • async/await
    • Object.values()
    • Object.entries()
    • String padding: padStart()和padEnd(),填充字符串达到当前长度
    • Object.getOwnPropertyDescriptors()
    • 函数参数列表结尾允许逗号
    • SharedArrayBuffer对象
    • Atomics对象
  • ES9 (ES2018)

    • 异步迭代(for await of)
    • Promise.finally()
    • Rest/Spread 属性
    • 新的正则表达式特性
      • 正则表达式反向断言(lookbehind)
      • 正则表达式dotAll模式
      • 正则表达式命名捕获组(Regular Expression Named Capture Groups)
      • 正则表达式 Unicode 转义
      • 非转义序列的模板字符串
  • ES10 (ES2019)

    • 新增了Array的 flat() 方法和 flatMap() 方法
    • 新增了String的 trimStart() 方法和 trimEnd() 方法
    • Object.fromEntries()
    • Symbol.prototype.description()
    • Function.prototype.toString() 现在返回精确字符,包括空格和注释
    • 简化 try {} catch {} ,修改 catch 绑定
  • ES11 (ES2020)

    • Promise.allSettled()
    • 可选链(Optional chaining)
    • 空值合并运算符(Nullish coalescing Operator)
    • import()
    • globalThis
    • BigInt
    • String.prototype.matchAll
  • ES12 (ES2021)

    • String.prototype.replaceAll()
    • Promise.any()
    • WeakRef
    • 逻辑赋值操作符(Logical Assignment Operators)
    • 数字分隔符(Numeric separators)

# 最有用的

  • Array.prototype.includes()
Array.prototype.includes()

[1, 2].includes(1) // true

1
2
3
4
  • 异步迭代(for await of)
async function getInfos(arr) {
  for await (let i of arr) {
    getData(i)
  }
}
1
2
3
4
5
  • Array的 flat() 方法和 flatMap() 方法

flat() 和 flatMap() 本质上就是是归纳(reduce) 与 合并(concat)的操作

[1, 2, [3, 4]].flat(Infinity); // [1, 2, 3, 4]

[1, 2, 3, 4].flatMap(a => [a**2]); // [1, 4, 9, 16]
1
2
3

# 推荐阅读