Created
February 18, 2010 07:46
-
-
Save kentaromiura/307449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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