ES2016指南

ES2016, officially known as ECMAScript 2016, was finalized in June 2016.

ES2016(正式称为ECMAScript 2016)于2016年6月完成。

Compared to ES2015, ES2016 is a tiny release for JavaScript, containing just two features:

与ES2015相比,ES2016是一个很小JavaScript版本,仅包含两个功能:

  • Array.prototype.includes

    Array.prototype.includes
  • Exponentiation Operator

    求幂运算符

Array.prototype.includes() (Array.prototype.includes())

This feature introduces a more readable syntax for checking if an array contains an element.

此功能引入了一种更具可读性的语法,用于检查数组是否包含元素。

With ES6 and lower, to check if an array contained an element you had to use indexOf, which checks the index in the array, and returns -1 if the element is not there.

在ES6及更低版本中,要检查数组是否包含元素,必须使用indexOf ,它检查数组中的索引,如果元素不存在,则返回-1

Since -1 is evaluated as a true value, you could not do for example

由于-1被评估为真实值,因此您无法执行例如

if (![1,2].indexOf(3)) {
  console.log('Not found')
}

With this feature introduced in ES2016 we can do

借助ES2016中引入的此功能,我们可以

if (![1,2].includes(3)) {
  console.log('Not found')
}

求幂运算符 (Exponentiation Operator)

The exponentiation operator ** is the equivalent of Math.pow(), but brought into the language instead of being a library function.

幂运算符**等同于Math.pow() ,但被带入语言而不是库函数。

Math.pow(4, 2) == 4 ** 2

This feature is a nice addition for math intensive JS applications.

该功能是数学密集型JS应用程序的不错的补充。

The ** operator is standardized across many languages including Python, Ruby, MATLAB, Lua, Perl and many others.

**运算符在包括Python,Ruby,MATLAB,Lua,Perl和许多其他语言的多种语言中得到了标准化。

翻译自: https://flaviocopes.com/es2016/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值