参考自 https://github.com/tc39/proposals/blob/master/finished-proposals.md
ES2016(ES7)
Array.prototype.includes-
ES2017(ES8)
Object.values/Object.entries- 字符串填充
''.padStart和''.padEnd Object.getOwnPropertyDescriptors- 函数参数列表和调用允许逗号结尾
- Async Functions 异步函数
Async/Await -
ES2018(ES9)
移除对“在‘带标签的模版字面量’中使用非法转义序列”的限制
rest / spread属性允许将对象的剩余属性收集到新对象中:const {x, ...y} = data- 正则表达式
?=先行断言(lookahead):/test(?=\d)/.test('test1') => true?!先行断言逆操作:/test(?!\d)/.test('test1') => false?<=后行断言(lookbehind):/(?<=Roger) Waters/.test('Roger Waters') => true?<!后行断言逆操作:/(?<!Roger) Waters/.test('Roger Waters') => false- 命名捕获组:
const result = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/.test('2018-01-01') => result.groups.year - s 标志
dotALL,使.符号可以匹配新行:/hi.+tom/s.test('hi,\ntom') => true - 使用 u标志 转义
\p{…}和\P{…}扩展 Unicode 匹配范围
Promise.prototype.finally异步迭代
for-await-of:for await (const line of readLines(filePath)) console.log(line)ES2019(ES10)
可选的 catch 绑定(Catch Binding):
try {} catch {}- JSON 成为 ECMAScript 的完全子集:在以前,行分隔符(\u2028)和段分隔符(\u2029)会导致
JSON.parse抛出语法错误异常 JSON.stringify改进,对于超出 Unicode 范围的转义序列,JSON.stringify() 会输出未知字符:JSON.stringify('\uDEAD'); // '"�"'Function.prototpye.toString()返回函数定义的内容,包括注释、空格等完整信息- 增加
Array.prorptype.flat和Array.prorptype.flatMap - 增加
String.prototype.trimStart和String.prototype.trimEnd - 增加
Object.fromEntries() Symbol.prototype.description输出 Symbol 描述:const a = Symbol('lzwme'); console.log(a.description); // lzwmeArray.prototype.sort()使用稳定的排序算法ES2020
变量名前加
#定义类私有变量- 增加
Promise.allSettled ?.可选链运算符:var age = user?.info?.getAge?.()??空值合并运算符(仅在null和undefined时合并):var age = user?.age ?? 18- Dynamic Import 动态导入:
import('./b.js').then import.meta<br />globalThis提供一种标准化方式访问全局对象- for-in 枚举顺序固定
BigInt安全的进行大数整型计算:var bigIntNum = 9007199254740993n; var bigIntNum = BigInt(9007199254740);-
ES2021
String.prototype.replaceAllPromise.any- 逻辑运算符与赋值表达式相结合
a ||= b // => a || (a=b)a &&= b // => a && (a=b)a ??= b // => a ?? (a=b)
- 数字分隔符
var a = 1_000 // => var a = 1000
