Object.prototype.getType = function () { var ctor = this.constructor; if (typeof (ctor) != 'function') return; var reg = new RegExp(/function\ ([\w\$\_][\w\$\_\d]*)\(.*/gmi); var matches = reg.exec(ctor.toString()); return (matches[1]); }; /* above for core javscript */ /* the following are for the core and the client, *not* stable! */ var Node = {}; Node.ELEMENT_NODE = 1; // Element Node.ATTRIBUTE_NODE = 2; // Attr Node.TEXT_NODE = 3; // Text Node.COMMENT_NODE = 8; // Comment Node.DOCUMENT_NODE = 9; // Document Node.DOCUMENT_FRAGMENT_NODE=11; // DocumentFragment getType = function (obj){ if (obj.navigator){ return 'Window'; } else if (obj.write){ return 'Document'; } else if(obj.tagName){ var ret = obj.tagName; if (ret == 'INPUT' || ret == 'SELECT'){ ret += ' ' + obj.type; } return ret; } else if(obj.nodeType){ switch(obj.nodeType){ case Node.ELEMENT_NODE: return obj.nodeName; case Node.ATTRIBUTE_NODE: return 'Attr'; case Node.TEXT_NODE: return 'Text'; case Node.COMMENT_NODE: return 'Comment' case Node.DOCUMENT_FRAGMENT_NODE: return 'DocumentFragment' default: } } else if (obj.constructor) { return obj.getType(); } };