Determining the object type (Useful tip)

To determine what kind of object type you have, this function may be useful.

This checks the type of the value passed in. If it is an object, then it looks at the constructor and returns the constructor's name. This works in Netscape 4.7 and MSIE version 5 and should work on other browsers, but check before deploying that it works on all the browsers you need it to.

Example code:

   <HTML>
   <BODY>
   <SCRIPT>
   // Determine object type
   function what_kind(aValue)
   {
   var myType = typeof(aValue);
   if (myType == "object")
   {
   return aValue.constructor.name;
   }
   else
   {
   return myType;
   }
   }
   document.write(what_kind(1));
   </SCRIPT>
   </BODY>
   </HTML>

See also:constructor.name