by Vali Shah

通过瓦利沙阿

JavaScript ES2019的新增功能 (What’s new in JavaScript ES2019)

Many of us know that there is a standard procedure for Javascript’s latest releases and a committee behind that. In this post, I will explain about who makes the final call on any new specification, what is the procedure for it, and what's new in ES2019.

我们中的许多人都知道Javascript的最新版本有一个标准过程,并且背后有一个委员会。 在本文中,我将解释谁最终对任何新规范进行了调用,执行的程序以及ES2019中的新增功能。

The language specification that drives JavaScript is called ECMAScript. There is a team behind that called Technical Committee 39 [TC39] that reviews every specification before adopting.

驱动JavaScript的语言规范称为ECMAScript。 背后有一个称为技术委员会39 [TC39]的团队,负责在采用之前审查每个规范

Every change goes through a process with stages of maturity.

每项变更都会经历一个成熟阶段的过程。

  • Stage 0: Ideas/Strawman

    阶段0:创意/稻草人

  • Stage 1: Proposals

    阶段1:提案

  • Stage 2: Drafts

    第二阶段:草稿

  • Stage 3: Candidates

    第三阶段:候选人

  • Stage 4: Finished/Approved

    阶段4:完成/批准

A feature which reaches Stage 4 will most likely be part of the language specification.

达到阶段4的功能很可能是语言规范的一部分。

Let's dive into the things which are added newly into the specification under ES2019.

让我们深入研究ES2019下规范中新添加的内容。

Array.prototype。{flat,flatMap} (Array.prototype.{flat,flatMap})

Array.prototype.flat() proposed to flatten arrays recursively up to the specified depth and returns a new array.

提议使用Array.prototype.flat()递归地将数组展平到指定depth并返回一个新数组。

Syntax: Array.prototype.flat(depth) depth — Default value 1, Use Infinity to flatten all nested arrays.

语法Array.prototype.flat(depth) depth —默认值1 ,使用Infinity展平所有嵌套数组。

const numbers = [1, 2, [3, 4, [5, 6]]];
// Considers default depth of 1
numbers.flat();
> [1, 2, 3, 4, [5, 6]]
// With depth of 2
numbers.flat(2);
> [1, 2, 3, 4, 5, 6]
// Executes two flat operations
numbers.flat().flat();
> [1, 2, 3, 4, 5, 6]
// Flattens recursively until the array contains no nested arrays
numbers.flat(Infinity)
> [1, 2, 3, 4, 5, 6]

Array.prototype.flatMap() maps each element using a mapping function and flattens the result into a new array. It’s identical to the map operation followed by a flat of depth 1.

Array.prototype.flatMap()使用映射函数映射每个元素,并将结果展平为新数组。 与地图操作相同,后跟一个depth 1flat

Syntax: Array.prototype.flatMap(callback) callback: function that produces an element of the new Array.

语法: Array.prototype.flatMap(callback) callback:产生新Array元素的function

const numbers = [1, 2, 3];
numbers.map(x => [x * 2]);
> [[2], [4], [6]]
numbers.flatMap(x => [x * 2]);
> [2, 4, 6]

Object.fromEntries (Object.fromEntries)

Object.fromEntries performs the reverse of Object.entries . It transforms a list of key-value pairs into an object.

Object.fromEntries执行与Object.entries相反的操作。 它将一组键值对转换为一个对象。

Syntax: Object.fromEntries(iterable) iterable: An iterable like Array or Map or objects implementing the iterable protocol

语法: Object.fromEntries(iterable) iterable:类似于ArrayMap可迭代对象或实现可迭代协议的对象

const records = [['name','Mathew'], ['age', 32]];
const obj = Object.fromEntries(records);
> { name: 'Mathew', age: 32}
Object.entries(obj);
> [['name','Mathew'], ['age', 32]];

String.prototype。{trimStart,trimEnd} (String.prototype.{trimStart, trimEnd})

trimStart() removes whitespace from the beginning of a string and trimEnd() removes whitespace from the end of a string.

trimStart()从字符串开头删除空格, trimEnd()从字符串结尾删除空格。

const greeting = ` Hello Javascript! `;
greeting.length;
> 19
greeting = greeting.trimStart();
> 'Hello Javascript! '
greeting.length;
> 18
greeting = 'Hello World!   ';
greeting.length;
> 15
greeting = greeting.trimEnd();
> 'Hello World!'
greeting.length;
> 12

可选的捕捉绑定 (Optional Catch Binding)

Prior to the new specification, it was required to have an exception variable bind to a catch clause. ES2019 made it optional.

在新规范之前,要求将异常变量绑定到catch子句。 ES2019使它成为可选。

// Before
try {...
} catch(error) {...
}
// After
try {...
} catch {...
}

This feature is useful when you want to completely ignore the error. Best practice is to consider handling an error.

当您要完全忽略该错误时,此功能很有用。 最佳实践是考虑处理错误。

There are cases where you know the possible error that could trigger on operations. You can ignore the catch block handling.

在某些情况下,您知道操作可能触发的错误。 您可以忽略catch块处理。

JSON⊂ECMAScript (JSON ⊂ ECMAScript)

The line separator (U+2028) and paragraph separator (U+2029) symbols are now allowed in string literals. Previously, these were treated as line terminators and resulted in SyntaxError exceptions.

现在,字符串文字中允许使用行分隔符(U + 2028)和段落分隔符(U + 2029)。 以前,这些被视为行终止符,并导致SyntaxError异常。

// Produces invalid string before ES2019
eval('"\u2028"');
// Valid in ES2019
eval('"\u2028"');

格式正确的JSON.stringify (Well-formed JSON.stringify)

Instead of unpaired surrogate code points resulting in single UTF-16 code units, ES10 represents them with JSON escape sequences.

ES10不会使用未配对的替代代码点生成单个UTF-16代码单元,而是使用JSON转义序列来表示它们。

JSON.stringify('\uD800');
> '"�"'
JSON.stringify('\uD800');
> '"\\ud800"'

Function.prototype.toString (Function.prototype.toString)

.toString() now returns exact slices of source code text, including whitespaces and comments.

.toString()现在返回源代码文本的精确片段,包括空格和注释。

function /* a comment */ foo () {}
// Previously:
foo.toString();
> 'function foo() {}'^ no comment^ no space
// Now:
foo.toString();
> 'function /* comment */ foo () {}'

Symbol.prototype.description (Symbol.prototype.description)

Read-only property that returns the optional description of a Symbol Object:

只读属性,它返回Symbol对象的可选描述:

Symbol('desc').toString();
> "Symbol(desc)"
Symbol('desc').description;
> "desc"
Symbol('').description;
> ""
Symbol().description;
> undefined

结论 (Conclusion)

TC39 keeps all the upcoming specifications which are in stage >1 of the process here. As a developer, It's important to keep tabs on what's happening around. There are many more exciting things coming up like static & private methods and fields in classes, Legacy RegEx, etc. Find out all the new things which are in the proposal stage here.

TC39保持所有即将来临的规格其在阶段>的凝固酶原1 SSħ ERE。 作为一个开发板的左右,它保持对周围发生的事情的标签是非常重要的。 还有更多令人兴奋的事情来了李柯静和在类的私有方法和字段,传统雷杰 X等找出所有的新东西是在提案STA GE ^ h ERE。

code = coffee + developer

code = co ffee + de veloper

Here are a few more interesting topics:

以下是一些更有趣的主题:

  • A quick overview of JavaScript Symbols

    JavaScript符号快速概述

  • How to adopt a git branching strategy

    如何采用git分支策略

  • An Introduction to Git Merge and Git Rebase: What They Do and When to Use Them

    Git合并和Git变基简介:它们做什么以及何时使用它们

翻译自: https://www.freecodecamp.org/news/whats-new-in-javascript-es2019-8af4390d8494/

JavaScript ES2019的新增功能相关推荐

  1. ABP Framework 5.2 RC 版本发布及新增功能介绍

    本文将介绍 ABP Framework 5.2 RC 版新增的主要功能: •单层解决方案模板•API 版本控制•源代码控制移除libs文件夹•对 Swagger UI 隐藏 ABP 默认端点•CMS ...

  2. java 1.8新增功能_睡觉时:新增的Java 8新增功能

    java 1.8新增功能 自Java 8推出以来,最有趣的功能是什么? Java 8最近庆祝了它的第一个生日,其主要版本已经在一年多以前了. 这当然值得庆祝. 自从最初的Java 8版本问世以来,已经 ...

  3. java 1.8新增功能_Java 8的新增功能(第二部分-可能会出现什么)

    java 1.8新增功能 免责声明:我不为Oracle工作,也不以任何方式代表Oracle. 此功能列表不是官方的. 作为"局外人",这只是我研究的一部分. 这是由三部分组成的系列 ...

  4. 睡觉时:新增的Java 8新增功能

    自Java 8推出以来,最有趣的功能是什么? Java 8最近庆祝了它的第一个生日,而主要版本刚刚一年多前发布. 这当然值得庆祝. 自从最初的Java 8版本问世以来,已经发布了六个更新. 这些更新中 ...

  5. Java 8的新增功能(第二部分–可能会出现什么)

    免责声明:我不为Oracle工作,也不以任何方式代表Oracle. 此功能列表不是官方的. 作为"局外人",这只是我研究的一部分. 这是由三部分组成的系列文章的第二部分. 在第一部 ...

  6. 以下是ECMAScript 2016、2017和2018中所有新增功能的示例

    by rajaraodv 通过rajaraodv 以下是ECMAScript 2016.2017和2018中所有新增功能的示例 (Here are examples of everything new ...

  7. day46-CSS3新增功能

    CSS3新增功能 1 CSS3选择器详解 1.1 基础选择器 通配选择器* 元素选择器E ID选择器#id CLASS选择器.class 群组选择器select1,selectN 1.2 层次选择器 ...

  8. SharePoint 2013 中的新增功能(与开发有关)

    了解 SharePoint 2013 中的新增特性和功能,包括新的云应用程序模型.开发工具.平台增强功能.移动应用程序以及更多其他功能. 适用范围: 云应用程序模型 SharePoint 2013 引 ...

  9. Visual C++ 新增功能(2003 - 2015)

    本页面包括从 Visual Studio 2003 到 Visual Studio 2015 的所有 Visual C++ 版本的"新增功能"页. 提供这些信息的目的是方便用户从早 ...

最新文章

  1. Ubuntu下makefile及gcc生成静态库动态库的简单使用举例
  2. 如何在Windows上使用Git创建一个可执行脚本?
  3. 入门干货之Electron的.NET实现-Electron.NET
  4. 常用软件包和环境配置(机器学习)
  5. ubuntu和centos 编译安装nginx及常用命令
  6. 认定信息网络传播行为应采用服务器标准,认定信息网络传播行为应采用“服务器标准”...
  7. vSphere 7简介:混合云的功能和技术
  8. Install Cockpit on Fedora/CentOS/RHEL
  9. java获取汉字首字母
  10. 酷q显示无法连接到服务器,本机酷Q与服务器nonebot建立通信
  11. 学生成绩管理系统测试用例C语言,学生成绩管理系统测试用例.docx
  12. 最新版面具隐藏root过检测教程(免刷机)
  13. 机器学习(MACHINE LEARNING)MATLAB实现层次分析法案例【AHP】
  14. html微博系统前端论文,微博平台设计与实现(毕业论文).doc
  15. 东华助手 v1.6.5
  16. 哪些安卓手机和IPhone手机浏览器可以安装油猴Tampermonkey插件
  17. 推荐阅读:《我在赶集网的两个月(完整版)》
  18. Java读文件和写文件
  19. linux4.4 内核 netlink,wpa_supplicant与内核nl80211通信之Generic Netlink
  20. 浅谈函数栈帧(Stack Frame)

热门文章

  1. Julia学习(1)——入门
  2. 【数字图像处理】Canny边缘检测详解及编程实现
  3. 使用runnable创建线程
  4. 9203-1117-实现数据库的查询功能
  5. 前端开发 常见的网页导航制作 0228
  6. css-适配布局类型-流式布局-响应式布局
  7. 查看SQL Server当前会话的隔离级别
  8. 小程序点击事件改变样式(普通js鼠标点击事件)
  9. Juqery ready的几种写法
  10. 一切都是骗局 Windows 8并不是很牛X