[thelist] using string value to typecast

shortestpath shortestpath at yahoo.com
Fri Aug 29 12:24:10 CDT 2003

Is there a way to use a string variable containing 
"Date", "String", or "Number", to typecast another 
value? I want to pass one of these to a function, 
and then use it to typecast a value. So for example, 
I would call: 

compare("Dec 25, 1995", "Jan 9, 1995", "Date");
compare("Dec 25, 1995", "Jan 9, 1995", "String");

where the compare function looks like this: 

function compare(a, b, objType) {
   if (objType == "Date")
      objType = Date.parse;

   if ( objType(a) < objType(b) )
      return -1
  if ( objType(a) > objType(b) )
      return 1

   // a must be equal to b
   return 0

thanks in advance,

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

More information about the thelist mailing list