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

两个操作数为undefined或者null会报错 #20

Open
anglesh opened this issue Oct 10, 2019 · 8 comments
Open

两个操作数为undefined或者null会报错 #20

anglesh opened this issue Oct 10, 2019 · 8 comments

Comments

@anglesh
Copy link

anglesh commented Oct 10, 2019

image

@lxfriday
Copy link
Collaborator

@anglesh 内部没有加数值判断导致的错误,这个你最好在调用函数之前检测传入的参数是否都是数值

@lxfriday
Copy link
Collaborator

@anglesh 先将不是数值的做一次转换处理或者提前禁止计算

@anglesh
Copy link
Author

anglesh commented Oct 21, 2019

后面能加下数值判断吗,因为每次调用都要判断,有点麻烦

@lxfriday
Copy link
Collaborator

@anglesh 这个可能不好加,因为不知道出现 undefined、null 是要转换为 0 呢还是直接报错

@lhwu
Copy link

lhwu commented Oct 28, 2019

那可以提供个参数供设置下吗,的确每次判断有点麻烦

@lxfriday
Copy link
Collaborator

@lhwu 预期需要处理的是什么样的数据?

@lhwu
Copy link

lhwu commented Oct 28, 2019

需要的是处理 undefined 的数据,常见的是本地开发时没碰到取值为undefined的数据,但是测试/生产时,数据可能取值到了 undefined(默认做0处理就行),导致报错。

而这时候需要再去对数据进行赋默认值操作,而且用到的地方比较多,每次操作都进行这个操作的话,比较烦杂。

所以觉得如果有个设置能统一处理下这种好。

careteenL added a commit to careteenL/number-precision that referenced this issue Dec 15, 2019
@xiaoqingb
Copy link

同求,遇到null or undefined统一返回成NaN应该就行了吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants