ECMAScript 新特性记录
作者: Byron 最后更新: 2023-07-13
ECMAScript 新特性记录
目录
背景
TC39 是一个由各大浏览器厂商、JavaScript 引擎厂商、各大技术社区、各大技术公司、各大高校、各大研究机构等组成的委员会, 负责制定 ECMAScript 标准.
标准修订和日程安排
TC39 打算在每年 7 月向 ECMA 大会提交一份规范以供批准. 以下是制定新规范的大致时间表:
- 2月1日: 生成候选草案.
- 2月-3月: 60天免版税退出期.
- 3月 TC39 会议: 第 4 阶段提案被合并, 最终语义被批准, 新的规范版本从 master 分支出来. 从这时起, 只接受编辑更改.
- 4月-6月: ECMA CC 和 ECMA GA 审查期.
- 7月: ECMA 大会批准新标准.
已完成的提案
已完成的提案是已经达到第 4 阶段的提案, 并包含在规范的最新草案中.
ECMAScript 2015(ES6)
let
和const
- 解构赋值
- 模板字符串
- 扩展运算符
- 箭头函数
- 函数参数默认值
- 剩余参数
- 对象属性简写
- 对象方法简写
- …
ECMAScript 2016(ES7)
Array.prototype.includes
Array.prototype.includes
TypedArray.prototype.includes
- 指数运算符:
**
Array.prototype.includes
提议 |
Array.prototype.includes
TypedArray.prototype.includes
指数运算符
ECMAScript 2017(ES8)
Object.values
/Object.entries
- String padding
String.prototype.padStart
String.prototype.padEnd
Object.getOwnPropertyDescriptors
- Trailing commas in function parameter lists and calls
- Async Functions
- Shared Memory and Atomics
Object.values
/Object.entries
Object.values
Object.entries
String padding
String.prototype.padStart
String.prototype.padEnd
Object.getOwnPropertyDescriptors
Trailing commas in function parameter lists and calls
函数参数列表和调用中的尾随逗号
Async Functions
Shared Memory and Atomics
共享内存和原子操作
ECMAScript 2018(ES9)
- Lifting template literal restriction
s
(dotAll
) flag for regular expressions- 修饰符:
s
RegExp.prototype.dotAll
- 修饰符:
- RegExp named capture groups
- Rest/Spread Properties
- RegExp Lookbehind Assertions
?<=
?<!
- RegExp Unicode Property Escapes
Promise.prototype.finally
- Asynchronous Iteration
for await...of
async function*
Lifting template literal restriction
解除模板字符串限制(
\
转义不再报错, 仅在作为标签函数的参数时生效)
s
(dotAll
) flag for regular expressions
提议 |
使用 s
修饰符, .
可以匹配任意字符, 包括换行符(\n
)
修饰符: s
RegExp.prototype.dotAll
RegExp named capture groups
Rest/Spread Properties
剩余/扩展属性
Rest Properties
Spread Properties
RegExp Lookbehind Assertions
?<=
?<!
RegExp Unicode Property Escapes
Promise.prototype.finally
Asynchronous Iteration
for await...of
Async generator functions
ECMAScript 2019(ES10)
- Optional
catch
binding - JSON superset (TBC)
Symbol.prototype.description
Function.prototype.toString
revisionObject.fromEntries
- Well-formed
JSON.stringify
String.prototype.{trimStart,trimEnd}
String.prototype.trimStart
String.prototype.trimEnd
Array.prototype.{flat,flatMap}
Array.prototype.flat
Array.prototype.flatMap
Optional catch
binding
catch
语句中的参数及括号可以省略
JSON superset
提议 |
Symbol.prototype.description
Function.prototype.toString
revision
Object.fromEntries
Well-formed JSON.stringify
String.prototype.{trimStart,trimEnd}
提议 |
String.prototype.trimStart
String.prototype.trimEnd
Array.prototype.{flat,flatMap}
提议 |
Array.prototype.flat
Array.prototype.flatMap
ECMAScript 2020(ES11)
String.prototype.matchAll
import()
BigInt
Promise.allSettled
globalThis
for-in
mechanics- Optional chaining: 可选链运算符
- Nullish coalescing Operator: 空值合并运算符
import.meta
String.prototype.matchAll
import()
BigInt
Promise.allSettled
globalThis
for-in
mechanics
Optional chaining
Nullish coalescing Operator
import.meta
ECMAScript 2021(ES12)
String.prototype.replaceAll
Promise.any
- WeakRefs
- Logical Assignment Operators: 逻辑赋值操作符
&&=
||=
??=
- Numeric Separators: 数字分隔符
String.prototype.replaceAll
Promise.any
WeakRefs
Logical Assignment Operators
&&=
||=
??=
Numeric Separators
ECMAScript 2022(ES13)
- Class Fields
- Field declarations(Public fields)
- Private fields
- RegExp Match Indices
- 修饰符
d
RegExp.prototype.hasIndices
- 修饰符
- Top-level
await
- Ergonomic brand checks for private fields
.at()
String.prototype.at
Array.prototype.at
TypedArray.prototype.at
- Accessible
Object.prototype.hasOwnProperty
:Object.hasOwn
- Class Static Block
- Error Cause
Class Fields
提议 |
Field declarations(Public fields)
Private fields
RegExp Match Indices
提议 |
修饰符 d
RegExp.prototype.hasIndices
Top-level await
Ergonomic brand checks for private fields
使 in
操作符可以用于检查私有字段
.at()
提议 |
String.prototype.at
Array.prototype.at
TypedArray.prototype.at
Accessible Object.prototype.hasOwnProperty
: Object.hasOwn
Class Static Block
Error Cause
ECMAScript 2023(ES14) Coming
- Array find from last
Array.prototype.findLast
Array.prototype.findLastIndex
TypedArray.prototype.findLast
TypedArray.prototype.findLastIndex
- Hashbang Grammar
- Symbols as WeakMap keys
- Change Array by Copy
Array.prototype.toReversed
Array.prototype.toSorted
Array.prototype.toSpliced
Array.prototype.with
TypedArray.prototype.toReversed
TypedArray.prototype.toSorted
TypedArray.prototype.with
Array find from last
提议 |
Array.prototype.findLast
Array.prototype.findLastIndex
TypedArray.prototype.findLast
TypedArray.prototype.findLastIndex
Hashbang Grammar
Symbols as WeakMap keys
Change Array by Copy
提议 |
Array.prototype.toReversed
Array.prototype.toSorted
Array.prototype.toSpliced
Array.prototype.with
TypedArray.prototype.toReversed
TypedArray.prototype.toSorted
TypedArray.prototype.with
ECMAScript 2024(ES15) Coming
- Well-Formed Unicode Strings
Atomics.waitAsync
- RegExp v flag with set notation + properties of strings