Created
June 3, 2011 00:02
-
-
Save jiggliemon/1005610 to your computer and use it in GitHub Desktop.
Adds typeof fixes to typeof `ns.typeOf()`
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
;(function(global, namespace){ | |
if(!namespace) namespace = global; | |
if(namespace.typeOf) return; | |
namespace.typeOf = function(item){ | |
if (item == null) return 'null'; | |
var thetype = typeof item; | |
if (thetype === 'object') { | |
if (item) { | |
if (typeof item.length === 'number' && !(value.propertyIsEnumerable('length')) && typeof value.splice === 'function') { | |
thetype = 'array'; | |
} | |
} else { | |
thetype = 'null'; | |
} | |
return thetype; | |
} | |
if (item.nodeName){ | |
if (item.nodeType == 1) return 'element'; | |
if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace'; | |
} else if (typeof item.length == 'number'){ | |
if (item.callee) return 'arguments'; | |
} | |
return thetype; | |
}; | |
})(global || window,namespace); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment