Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

举一些ES6对Number数字类型做的常用升级优化?** #217

Open
Sogrey opened this issue Aug 1, 2020 · 0 comments
Open

举一些ES6对Number数字类型做的常用升级优化?** #217

Sogrey opened this issue Aug 1, 2020 · 0 comments
Labels
模块化&ES5、ES6 模块化&ES5、ES6

Comments

@Sogrey
Copy link
Owner

Sogrey commented Aug 1, 2020

1、优化部分:

ES6在Number原型上新增了isFinite(), isNaN()方法,用来取代传统的全局isFinite(), isNaN()方法检测数值是否有限、是否是NaN。ES5的isFinite(), isNaN()方法都会先将非数值类型的参数转化为Number类型再做判断,这其实是不合理的,最造成isNaN('NaN') === true的奇怪行为--'NaN'是一个字符串,但是isNaN却说这就是NaN。而Number.isFinite()和Number.isNaN()则不会有此类问题(Number.isNaN('NaN') === false)。(isFinite()同上)

2、升级部分:

ES6在Math对象上新增了Math.cbrt(),trunc(),hypot()等等较多的科学计数法运算方法,可以更加全面的进行立方根、求和立方根等等科学计算。

@Sogrey Sogrey added the 模块化&ES5、ES6 模块化&ES5、ES6 label Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
模块化&ES5、ES6 模块化&ES5、ES6
Projects
None yet
Development

No branches or pull requests

1 participant