what‘s news in Es6+ (es6+新增api)

今天药忘吃喽~ 2022-09-05 01:41 242阅读 0赞

news in Es6+ (es6+新增api)

TC39 stages

  • stage 0 提案

    新的功能计划或一个还没有实现的需求。需求讨论阶段

  • [stage 1] (https://github.com/tc39/proposals/blob/master/stage-1-proposals.md) 提案

    这个阶段主要是解决存在的问题和定义API结构

  • stage 2 草案

    stage1的问题已经解决。这些新特性规范预计会出现在未来的版本中

  • stage 3 选举

    提案被彻彻底底细致的查看,不遗余力。这是距离成为标准前的最后一步

  • stage 4 完成

    已经成为规范标准

接下来,我看看就来看看各个功能出现的时间

ES2016

  • Array.prototype.includes(): 确定数组中是否有指定项。String.prototype.contains() 废弃
  • 幂运算 ** 和 **=a**b a的b次方,相当于 Math.pow(a, b)a= a**b ---> a**=b

ES2017

  • Object.values / Object.entries: 返回对象值的数组 、返回对象 [键,值] 的二维数组
  • Trailing commas :函数参数最后可以使用逗号(定义和调用都可)
  • async functions: 异步函数 async/await 写法出现
  • Object.getOwnPropertyDescriptors(): 返回自己属性的相关描述

    1. const object1 = {
    2. property1: 42
    3. };
    4. const descriptors1 = Object.getOwnPropertyDescriptors(object1);
    5. console.log(descriptors1.property1.writable);
    6. // expected output: true
    7. console.log(descriptors1.property1.value);
    8. // expected output: 42
  • String.prototype.padStart() / String.prototype.padEnd(strLen, 'pad str'): 在字符串的头部、尾部填充字符串到 strLen

ES2018

  • Promise.prototype.finally: 成功失败都会执行finally
  • ... : rest and spread opraters: 解构语法
  • for-await-of (Asynchronous iteration): 异步迭代器
  • 正则语法改进:增加 flag s

    1. console.log(/A.B/.test("A\nB")); // false
    2. console.log(/A.B/s.test("A\nB")); // true

ES2019

  • Array.prototype.flat(): 数组扁平化
  • Array.prototype.flatMap(): 数组扁平化后map
  • Object.fromEntries(): Object.entries 的反向操作
  • String.prototype.trimStart() / String.prototype.trimEnd(): 去除字符串前、后空格
  • Symbol.prototype.description: 获取 Symbol 的描述

    1. console.log(Symbol('desc').description);
    2. // expected output: "desc"
    3. console.log(Symbol.iterator.description);
    4. // expected output: "Symbol.iterator"
  • Optional catch binding: 可选的 catch 参数

    1. try{}catch (e){}
    2. // new
    3. try{} catch {}

ES2020

  • String.prototype.matchAll():
  • dynamic imports: 之前都是 静态 import,动态 import 支持后可以完全替代 require
  • BigInt : 大数
  • Promise.assSettled(): 遇到过 Bluebird 的 allsettled 实现结果不一致问题。
  • globalThis: 之前都是使用 window、 self在浏览器里,globalThis 可以用在 node 和 浏览器
  • 可选链操作 ?. :
  • null、undefined 操作符??a ?? b 如果a为null或undefined 结果为b

ES2021

  • String.prototype.replaceAll(): 移除所有匹配
  • Promise.any(): 返回第一个 resolve
  • Underscore as a numeric separator: 1_000 === 1000
  • Logical assignment operators(&&=, ||=, ??=)
  • WeakRefs and Finalizers: This is a class that helps you create weak references to objects, so they can be garbage collected. A FinalizationRegistryobject lets you register a callback that will allow you to invoke when the object is garbage collected. : weak 弱引用,可以被垃圾回收

ES2022

thanks

  • what’s new in es2022?

发表评论

表情:
评论列表 (有 0 条评论,242人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ES6新增内容

    1、map、filter和reduce的区别 map 作用是生成一个新数组,遍历原数组,将每个元素拿出来做一些变换然后放入到新的数组中。map 的回调函数接受三个参数,分

    相关 ES6新增的循环

    1、以前for循环,for in循环 2、ES6新增循环:for of 循环:遍历(迭代,循环)整个对象, 两者的区别: for in循环:既可以循环数组,