网站首页 > 博客文章 正文
就在刚 4 个小时前,TC39 将以下特性加入到了 ES2019 中。让我们来看看这些新的特性给我们带来了什么样的改变。
ES2019 新特性:
?? Array#{flat,flatMap}
?? Object.fromEntries
?? String#{trimStart,trimEnd}
?? Symbol#description
?? try { } catch {} // optional binding
?? JSON ? ECMAScript
?? well-formed JSON.stringify
?? stable Array#sort
?? revised Function#toString
JSON ? ECMAScript (JSON superset)
行分隔符(U + 2028)和段分隔符(U + 2029)符号现在允许在字符串文字中,与 JSON 匹配。 以前,这些符号在字符串文字中被视为行终止符,因此使用它们会导致 SyntaxError 异常。
well-formed JSON.stringify
更加友好的 JSON.stringify (修复了对于一些超出范围的 unicode 展示错误的问题。)
如果输入 Unicode 格式但是超出范围的字符,在原先 JSON.stringify 返回格式错误的 Unicode 字符串:
JSON.stringify('\uD800'); // → '"?"'
现在实现了一个改变 JSON.stringify 的第 3 阶段提案,因此它为其输出转义序列,使其成为有效 Unicode(并以 UTF-8 表示):
JSON.stringify('\uD800'); // → '"\ud800"'
stable Array#sort
在以前,sort 函数中,10 个以上元素的数组 V8 使用不稳定的 QuickSort(快排。现在,使用稳定的 TimSort 算法。)
TimSort 算法: https://en.wikipedia.org/wiki/Timsort
revised Function#toString
Function.prototype.toString() 现在返回精确字符,包括空格和注释。原先和现在的比较:
// Note the comment between the `function` keyword // and the function name, as well as the space following // the function name. function /* a comment */ foo () {} // Previously: foo.toString(); // → 'function foo() {}' // ^ no comment // ^ no space // Now: foo.toString(); // → 'function /* comment */ foo () {}'
Array #{flat, flatMap}
数组降维,递归地将数组展平到指定的深度,默认为 1。
// Flatten one level: const array = [1, [2, [3]]]; array.flat(); // → [1, 2, [3]] // Flatten recursively until the array contains no more nested arrays: array.flat(Infinity); // → [1, 2, 3] [2, 3, 4].flatMap((x) => [x, x * 2]); // → [2, 4, 3, 6, 4, 8]
Object.fromEntries
Object.fromEntries(Object.entries(object))≈ 对象
它类似于 Lodash的_.fromPairs。
String#{trimStart,trimEnd}
前后的空白符可以指定一边去除。
const string = ' hello world '; string.trimStart(); // → 'hello world ' string.trimEnd(); // → ' hello world' string.trim(); // → 'hello world'
Symbol.prototype.description
通过工厂函数 Symbol()创建符号时,您可以选择通过参数提供字符串作为描述:
const sym = Symbol('The description');
以前,访问描述的唯一方法是将符号转换为字符串:
assert.equal(String(sym), 'Symbol(The description)');
现在引入了 getter Symbol.prototype.description 以直接访问描述:
assert.equal(sym.description, 'The description');
try {} catch {}
现在try {} catch {} 有了更加简便的方法,变成了可选型。
在以前
try {} catch (e) {}
现在
更多提案:
https://github.com/tc39/proposals/blob/master/finished-proposals.md
- 上一篇: 蛋白质翻译和加工转运的游离核糖体途径(一)
- 下一篇: 求职者看过来!最常见的五个面试问题如何答
猜你喜欢
- 2024-09-15 做出这31个改变,我收获到了最快乐的一年
- 2024-09-15 求职者看过来!最常见的五个面试问题如何答
- 2024-09-15 蛋白质翻译和加工转运的游离核糖体途径(一)
- 2024-09-15 JDK 11 已处于特性冻结状态,看看 Java 11 API 变更提案
- 2024-09-15 手动实现一致性 Hash 算法(一致性hash原理)
- 2024-09-15 浅析 Spark Shuffle 内存使用(spark基于内存的运算要快多少倍)
- 2024-09-15 Java 集合中的排序算法浅析(java集合中的排序是怎么实现的)
- 2024-09-15 KeSort:验证泛型集合的OpenJKK排序方法
- 2024-09-15 JS数组排序(js数组排序的几种方法是什么)
- 2024-09-15 最近邻算法比较:暴力求解 vs. 空间索引
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)