ES2016指南

阅读: 评论:0

ES2016指南

ES2016指南

  • Array.prototype.includes()

    Array.prototype.includes()

  • Exponentiation Operator

    求幂运算符

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和许多其他语言的多种语言中得到了标准化。

翻译自: /

本文发布于:2024-02-04 05:10:19,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170699809252352.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:es在线文档
标签:指南
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23