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.
<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 |
| Prev | Home | Next |
| detachEvent() | Up | Developing JavaScript source code |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||