HighDots Forums  

Re: 'Number Expected' problems

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: 'Number Expected' problems in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Richard Cornford
 
Posts: n/a

Default Re: 'Number Expected' problems - 01-05-2005 , 07:14 PM






Lee wrote:
Quote:
B. Fletcher said:
snip
Also, this line:

return parseInt(String.valueOf(randoms[r++]));

seems to be explicitely converting a number to a string,
and then converting it back to a number again. I'm
curious as to why that seems like a good idea.
I am not so sure that is what it is doing. The - valueOf - method that
is being called is the method of the String function (the String object
constructor) and while the - valueOf - method of a String object
instance should return the string primitive value of that string, surly
the - valueOf - method of the - String - constructor is the one
inherited through - Function.prototype -. And as - Function.prototype -
has no - valueOf - property of its own the method called will be the one
from - Object.prototype -, which is specified as returning - this -; the
String constructor function in this case.

However, none of those - valueOf - methods take an argument anyway.

If - String.valueOf( whatever ) - returns a reference to a function
then - parseInt - will type-convert its argument to a string, which will
not resemble a number. And so - parseInt - will return - NaN -, which is
a number (sort of) but maybe not in the context of the
Array.prototype.sort method.

I recall a thread about 6 months ago in which IE producing a "Number
expected" error from Array.prototype.sort was discussed, but I cannot
remember the conclusion. Groups.google.com might be able to turn
something up (assuming they haven't completely messes google groups up
by now).

Richard.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.