IE中不存在Number.isNaN [英] Number.isNaN doesn't exist in IE

查看:828
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆