ECMAScript 新特性记录

作者: Byron 最后更新: 2023-07-13

ECMAScript 新特性记录


目录

背景

TC39 是一个由各大浏览器厂商、JavaScript 引擎厂商、各大技术社区、各大技术公司、各大高校、各大研究机构等组成的委员会, 负责制定 ECMAScript 标准.

标准修订和日程安排

The TC39 Process

TC39 打算在每年 7 月向 ECMA 大会提交一份规范以供批准. 以下是制定新规范的大致时间表:

  • 2月1日: 生成候选草案.
  • 2月-3月: 60天免版税退出期.
  • 3月 TC39 会议: 第 4 阶段提案被合并, 最终语义被批准, 新的规范版本从 master 分支出来. 从这时起, 只接受编辑更改.
  • 4月-6月: ECMA CC 和 ECMA GA 审查期.
  • 7月: ECMA 大会批准新标准.

已完成的提案

Finished Proposals

已完成的提案是已经达到第 4 阶段的提案, 并包含在规范的最新草案中.

ECMAScript 2015(ES6)

  • letconst
  • 解构赋值
  • 模板字符串
  • 扩展运算符
  • 箭头函数
  • 函数参数默认值
  • 剩余参数
  • 对象属性简写
  • 对象方法简写

ECMAScript 2016(ES7)

  • Array.prototype.includes
    • Array.prototype.includes
    • TypedArray.prototype.includes
  • 指数运算符: **

Array.prototype.includes

提议 |

Array.prototype.includes

规范 | mdn |

TypedArray.prototype.includes

规范 | mdn |

指数运算符

提议 | 规范 | mdn |

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

提议 | 规范 | mdn |

Object.entries

提议 | 规范 | mdn |

String padding

String.prototype.padStart

提议 | 规范 | mdn |

String.prototype.padEnd

提议 | 规范 | mdn |

Object.getOwnPropertyDescriptors

提议 | 规范 | mdn |

Trailing commas in function parameter lists and calls

提议 | 规范 | mdn |

函数参数列表和调用中的尾随逗号

Async Functions

提议 | 规范 | mdn |

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

提议 | 规范 | mdn |

解除模板字符串限制(\转义不再报错, 仅在作为标签函数的参数时生效)

s(dotAll) flag for regular expressions

提议 |

使用 s 修饰符, . 可以匹配任意字符, 包括换行符(\n)

修饰符: s

规范 | mdn |

RegExp.prototype.dotAll

规范 | mdn |

RegExp named capture groups

提议 | 规范 | mdn |

Rest/Spread Properties

剩余/扩展属性

Rest Properties

提议 | 规范 | mdn |

Spread Properties

提议 | 规范 | mdn |

RegExp Lookbehind Assertions

提议 | 规范 | mdn |

?<=

?<!

RegExp Unicode Property Escapes

提议 | 规范 | mdn |

Promise.prototype.finally

提议 | 规范 | mdn |

Asynchronous Iteration

提议 | 规范 | mdn |

for await...of

规范 | mdn

Async generator functions

规范 | mdn

ECMAScript 2019(ES10)

  • Optional catch binding
  • JSON superset (TBC)
  • 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

Optional catch binding

提议 | 规范 | mdn |

catch 语句中的参数及括号可以省略

JSON superset

提议 |

Symbol.prototype.description

提议 | 规范 | mdn |

Function.prototype.toString revision

提议 | 规范 | mdn |

Object.fromEntries

提议 | 规范 | mdn |

Well-formed JSON.stringify

提议 | 规范 | mdn |

String.prototype.{trimStart,trimEnd}

提议 |

String.prototype.trimStart

规范 | mdn |

String.prototype.trimEnd

规范 | mdn |

Array.prototype.{flat,flatMap}

提议 |

Array.prototype.flat

规范 | mdn |

Array.prototype.flatMap

规范 | mdn |

ECMAScript 2020(ES11)

  • String.prototype.matchAll
  • import()
  • BigInt
  • Promise.allSettled
  • globalThis
  • for-in mechanics
  • Optional chaining: 可选链运算符
  • Nullish coalescing Operator: 空值合并运算符
  • import.meta

String.prototype.matchAll

提议 | 规范 | mdn |

import()

提议 | 规范 | mdn |

BigInt

提议 | 规范 | mdn |

Promise.allSettled

提议 | 规范 | mdn |

globalThis

提议 | 规范 | mdn |

for-in mechanics

提议 | 规范 | mdn |

Optional chaining

提议 | 规范 | mdn |

Nullish coalescing Operator

提议 | 规范 | mdn |

import.meta

提议 | 规范 | mdn |

ECMAScript 2021(ES12)

  • String.prototype.replaceAll
  • Promise.any
  • WeakRefs
  • Logical Assignment Operators: 逻辑赋值操作符
    • &&=
    • ||=
    • ??=
  • Numeric Separators: 数字分隔符

String.prototype.replaceAll

提议 | 规范 | mdn |

Promise.any

提议 | 规范 | mdn |

WeakRefs

提议 | 规范 | mdn |

Logical Assignment Operators

提议 | 规范 |

&&=

mdn

||=

mdn

??=

mdn

Numeric Separators

提议 | 规范 | mdn |

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)

规范 | mdn |

Private fields

规范 | mdn |

RegExp Match Indices

提议 |

修饰符 d

RegExp.prototype.hasIndices

规范 | mdn |

Top-level await

提议 | 规范 | mdn |

Ergonomic brand checks for private fields

提议 | 规范 | mdn |

使 in 操作符可以用于检查私有字段

.at()

提议 |

String.prototype.at

规范 | mdn |

Array.prototype.at

规范 | mdn |

TypedArray.prototype.at

规范 | mdn |

Accessible Object.prototype.hasOwnProperty: Object.hasOwn

提议 | 规范 | mdn |

Class Static Block

提议 | 规范 | mdn |

Error Cause

提议 | 规范 | mdn |

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

规范 | mdn |

Array.prototype.findLastIndex

规范 | mdn |

TypedArray.prototype.findLast

规范 | mdn |

TypedArray.prototype.findLastIndex

规范 | mdn |

Hashbang Grammar

提议 | 规范 | mdn |

Symbols as WeakMap keys

提议 | mdn |

Change Array by Copy

提议 |

Array.prototype.toReversed

规范 | mdn |

Array.prototype.toSorted

规范 | mdn |

Array.prototype.toSpliced

规范 | mdn |

Array.prototype.with

规范 | mdn |

TypedArray.prototype.toReversed

规范 | mdn |

TypedArray.prototype.toSorted

规范 | mdn |

TypedArray.prototype.with

规范 | mdn |

ECMAScript 2024(ES15) Coming

  • Well-Formed Unicode Strings
  • Atomics.waitAsync
  • RegExp v flag with set notation + properties of strings