JavaScript: get_class
/**
* Returns the name of the class of an object
*
* NOTE: This function doesn't work with 'native code', only with user generated classes.
*
* based on http://magnetiq.com/2006/07/10/finding-out-class-names-of-javascript-objects/
*
* @param object The object
* @returns mixed Returns the name of the class of which object is an instance. Returns FALSE if object is not an object.
*/
function get_class(obj)
{
if(obj && obj.constructor && obj.constructor.toString)
{
var arr = obj.constructor.toString().match(/function\s*(\w+)/);
return (arr && (arr.length==2?arr[1]:undefined));
}
else
{
return undefined;
}
}
Filed under: Webdev
Trackback(s)
What's trackback?
A trackback is a kind of a source link. If i was finding an interesting entry in another blog, that i am commenting in my own blog, i am linking to the original message via the trackback. Has someone commented one of my entries in his/her weblog, you can find this link here under trackbacks, too. More informations about trackback are in the Wikipedia for example.
Trackback URL: /trackback/javascript-getclass/
Trackbacks aren't available anymore.