What’s Coming Up in JavaScript 2018
Posted 螺钉英语
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了What’s Coming Up in JavaScript 2018相关的知识,希望对你有一定的参考价值。
What’s Coming Up in javascript 2018: Async Generators, Better Regex
Terlson is particularly excited about the improvements to regular expressions (where much of the work has been done by the V8 team, who already have early implementations of the four main features), as this is an area where the language has fallen behind.
Tealson对正则表达式的改进非常兴奋(其中大部分都是由工作于V8引擎的团队完成的,他们已经完成了四个主要的特性的早期实现),因为这是这门语言落后的地方。
“ECMAScript regexps haven’t advanced significantly since day one of JavaScript; pretty much every other programming language has regexp libraries with far more advanced capabilities than ECMAScript regexps.”
“自JavaScript诞生起,ECMAScript正则表达式没有过很大的进步提升,几乎其他所有编程语言的正则表达式库的功能更加高级。”
ECMAScript 6 included some minor updates but he views ECMAScript 2018 as “the first update to significantly change the game for how you write regular expressions”.
ECMAScript 6 包含了 一些小的更新 ,但是他将ECMAScript2018视为“第一次明显改变你如何写正则表达式的更新“。
The dotAll flag makes the dot character match all characters, instead of failing to match some line breaks (like or f). “You can’t use dot unless you’re in multiline mode and you don’t care about line endings,” he points out.
dotAll 标志 使点字符匹配所有字符,而不会对匹配一些换行(如 或f)无效。“除非你在处于多行模式下并且你不在意每行的结束,否则你就不能使用点字符,”他指出。
Workarounds for that have created unnecessarily complex regexps and Terlson expects that “pretty much everyone will always engage that mode in regexp”.
这方面的变通方法创造了不必要的复杂的正则表达式,并且Terlson期待:“每一个人都会在正则表达式中使用该模式”。
Named capture groups are similar to named groups in many other languages, where you can name the different portions of a string that a regular expression matches and treat that as an object.
命名捕获组 类似于一些其他语言的命名组,你可以在命名不同部分的正则表达式匹配的字符串,并将其视为对象。
“It’s almost like a comment in your regular expression to explain what the group is trying to capture by giving it a name,” he explains.
“这几乎等同于在你的正则表达式中添加注释,通过赋予它一个名字来解释这个组试图捕捉的内容,”他解释道。
“This part of the pattern is the month, this is the date of birth… it’s really helpful to make your patterns maintainable by someone else in the future.”
“这部分模式就是月份,这是出生日期......这对于未来其他人维护你的模式真的很有帮助。”
There are other proposals for free spacing, which tells the regexp engine to ignore white space and line breaks inside a pattern match, and comments, which will allow comments at the end of lines after spaces, which may be included in future versions of ECMAScript and would further improve maintainability.
还有关于空字符的提案,告诉了正则表达式引擎忽略模式匹配中的空格,换行以及注释,并且允许在空格后的行尾添加注释,这种特性可能包含了在将来的ECMAScript版本中进一步提高可维护性。
Previously ECMAScript has lookaheads but not lookbehinds. “People did tricks like reversing the string and then doing the match, or some other hacks,” notes Terlson.
以前的ECMAScript只有先行断言而没有后行断言。“人们使用了一些技巧,就像反转字符串,然后进行匹配,或者一些其他hacks,” Terslon强调。
This will be particularly useful for regexps that do find and replace. “What you look at doesn’t become part of your match, so if you’re replacing a number that has a dollar sign on either side you can do that without having to do extra work to put the dollar sign back in.” The ECMAScript lookbehind allows variable length lookbehinds like C#, rather than only the fixed length patterns of Perl lookbehinds.
这对于查找和替换的正则表达式非常有用。 “你看到的没有变成你匹配的一部分,所以如果你要替换前后任何一侧有美元符号的数字,你就可以做到这一点无需做额外的工作将美元符号重新放回去” ECMAScript 的后行断言允许像C#中那样可变长度的后行断言,而不是仅仅的像Perl的固定长度模式。
by Mary Branscombe
particularly 特别,尤其
implementation 实施,实践
advance 前进
significantly 显著地
minor 较小的
flag 标示
dot 点
character 字符
line break 换行
multiline 多行
point out 指出
Workaround 变通方法
unnecessarily 不必要地
pretty much 几乎,差不多
engage 参与,使用
capture 捕获
portion 部分
string 串
object 对象
comment 评论,注解
maintainable 可维护的
proposal 提议
white space 空格
maintainability 可维护性
trick 机谋,恶作剧
reverse 反转
dollar 美元
sign 符号
variable 可变的
length 长度
rather than 而不是
fix 固定的
Welcome to NODEING English. We're here to put a dent in the universe.
以上是关于What’s Coming Up in JavaScript 2018的主要内容,如果未能解决你的问题,请参考以下文章
the ten capability that you have to get in the coming 2017