what‘s news in Es6+ (es6+新增api)
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()
: 返回自己属性的相关描述const object1 = {
property1: 42
};
const descriptors1 = Object.getOwnPropertyDescriptors(object1);
console.log(descriptors1.property1.writable);
// expected output: true
console.log(descriptors1.property1.value);
// 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
console.log(/A.B/.test("A\nB")); // false
console.log(/A.B/s.test("A\nB")); // true
ES2019
Array.prototype.flat()
: 数组扁平化Array.prototype.flatMap()
: 数组扁平化后mapObject.fromEntries()
: Object.entries 的反向操作String.prototype.trimStart() / String.prototype.trimEnd()
: 去除字符串前、后空格Symbol.prototype.description
: 获取 Symbol 的描述console.log(Symbol('desc').description);
// expected output: "desc"
console.log(Symbol.iterator.description);
// expected output: "Symbol.iterator"
Optional catch binding
: 可选的 catch 参数try{}catch (e){}
// new
try{} catch {}
ES2020
String.prototype.matchAll()
:dynamic imports
: 之前都是 静态 import,动态 import 支持后可以完全替代 requireBigInt
: 大数Promise.assSettled()
: 遇到过 Bluebird 的 allsettled 实现结果不一致问题。globalThis
: 之前都是使用 window、 self在浏览器里,globalThis 可以用在 node 和 浏览器- 可选链操作
?.
: - null、undefined 操作符
??
:a ?? b
如果a为null或undefined 结果为b
ES2021
String.prototype.replaceAll()
: 移除所有匹配Promise.any()
: 返回第一个 resolveUnderscore 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?
还没有评论,来说两句吧...