SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Chambéry (France)
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up typeof NaN == 'number' on IE win, X contrib

    Hi Mike,

    Found a "bug" on a function of the really great X cross-browser library.
    When testing the type of a variable which value is NaN, IE (on windows) returns 'number'.
    It may cause problems on functions like xLeft ...

    Code:
    alert (typeof NaN);
    Code:
    function xNum() {
      for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
      return true;
    }
    Hope this is clear

    Daniel, Olivier, Pierre

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44° 56.537' W 123° 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NaN is a property of the number object. NaN has peculiar behavior and really can't be used directly. For instance this returns false: NaN==NaN. isNaN does not suffer from these ambiguities.

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks pgira and JVLB :-)

    I'm having puter problems so I can't experiment with it right now, but I will next week.

    If typeof(NaN) == 'number' then it's not a bug. But still, your addition to xNum looks good.

    I have to think about this some more. Any other ideas are welcome.


  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pgira, just wanted to let you know that I made your code-change to xNum and it will be in the next release.

    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •