IE中不存在Number.isNaN

编程入门 行业动态 更新时间:2024-10-19 21:23:17
本文介绍了IE中不存在Number.isNaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么IE不支持 Number.isNaN 功能?我不能使用简单的isNan代替Number.isNaN,因为这些函数是不同的! 例如:

Why does not IE support the Number.isNaN function? I can't use simple isNan instead of Number.isNaN 'cause these functions are different! For example:

Number.isNaN("abacada") != isNaN("abacada") //false != true

我需要抽象字符串和数字并检查,是否有一些var确实包含 NaN (我的意思是NaN常量,但不是数字值,例如字符串).

I need to abstract string and number and check, is some var really contains NaN (I mean NaN constant, but not-a-number value like strings).

someobj.someopt = "blah"/0; someobj.someopt2 = "blah"; someobj.someopt3 = 150; for(a in someobj) if(Number.isNaN(someobj[a])) alert('!');

该代码应显示警报1次.但是,如果我将Number.isNaN更改为isNaN,它将发出2次警报.有区别.

That code should show alert for 1 time. But if I will change Number.isNaN to isNaN, it will alert 2 times. There are differences.

可能存在一些替代功能吗?

May be there is some alternative function exists?

推荐答案

为什么IE不支持 Number.isNaN 功能?

这对于Stack Overflow来说是相当不合时宜的,但是根据 Number.isNaN 的MDN页面,未在任何标准—中定义它仅在ECMAScript 6的规范草案中.而且Internet Explorer并不是唯一不支持它的浏览器.

That's rather off-topic for Stack Overflow, but according to the MDN page for Number.isNaN, it's not defined in any standard — it's only in the draft spec for ECMAScript 6 — and Internet Explorer is not the only browser that doesn't support it.

可能存在一些替代功能吗?

May be there is some alternative function exists?

并非如此,但是您可以轻松地定义一个:

Not really, but you can easily define one:

function myIsNaN(o) { return typeof(o) === 'number' && isNaN(o); }

或者,如果您愿意:

function myIsNaN(o) { return o !== o; }

更多推荐

IE中不存在Number.isNaN

本文发布于:2023-11-28 07:18:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   Number   isNaN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!