Skip to content

Instantly share code, notes, and snippets.

@kentaromiura
Created February 18, 2010 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentaromiura/307449 to your computer and use it in GitHub Desktop.
Save kentaromiura/307449 to your computer and use it in GitHub Desktop.
/*
This is a fix for $type function to make it work with ActiveXObject too :) - optimized for size
*/
function $type(obj) {
if (obj == undefined) return false;
if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name;
if (obj.nodeName) {
switch (obj.nodeType) {
case 1: return 'element';
case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
}
} else if (typeof obj.length == 'number') {
if (obj.callee) return 'arguments';
else if (typeof (obj.item) == 'unknown'|| obj.item) return 'collection';
}
return typeof obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment