ES9-2018

1. rest 参数和扩展运算符

function foo(...args) {
  console.log(args)
}

foo(1, 2, 3) // [1, 2, 3]

2. 正则表达式命名捕获组

const RE_DATE = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/

const matchObj = RE_DATE.exec('1999-12-31')

const year = matchObj.groups.year // 1999

const month = matchObj.groups.month // 12

const day = matchObj.groups.day // 31

3. 正则表达式反向断言

const RE_TWICE = /^(?<word>[a-z]+)(?!\k<word>)$/

RE_TWICE.test('abc') // true

RE_TWICE.test('abcc') // false

RE_TWICE.test('abab') // false

RE_TWICE.test('ababa') // true

4. 正则表达式 Unicode 转义

;/\u{61}/.test('a') / // true
  𠮷 /
  u.test('𠮷') // true

5. Promise.prototype.finally()

Promise.resolve(123)
  .then((res) => {
    console.log(res) // 123
  })
  .finally(() => {
    console.log('finally')
  })

6. Object.fromEntries()

Object.fromEntries([
  ['foo', 'bar'],
  ['baz', 42],
]) // { foo: "bar", baz: 42 }

for...of 循环 和 await

async function foo() {
  for await (const x of createAsyncIterable(['a', 'b'])) {
    console.log(x)
  }
}

foo() // logs a, then b