Skip to content

Instantly share code, notes, and snippets.

@jiggliemon
Created June 3, 2011 00:02
Show Gist options
  • Save jiggliemon/1005610 to your computer and use it in GitHub Desktop.
Save jiggliemon/1005610 to your computer and use it in GitHub Desktop.
Adds typeof fixes to typeof `ns.typeOf()`
;(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