Skip to content

Instantly share code, notes, and snippets.

@littlepsylo
Forked from WebReflection/typeOf.js
Created October 4, 2013 09:09
Show Gist options
  • Save littlepsylo/6823155 to your computer and use it in GitHub Desktop.
Save littlepsylo/6823155 to your computer and use it in GitHub Desktop.
var typeOf = (function(Object, RegExp){
// WTFPL License - http://en.wikipedia.org/wiki/WTFPL
// thanks to @jdalton and @ljharb
var toString = Object.prototype.toString,
cache = (Object.create || Object)(null);
return function typeOf(Unknown) {
var asString = typeof Unknown;
return asString == 'object' ? (
Unknown === null ? 'null' : (
cache[asString = toString.call(Unknown)] || (
cache[asString] = asString
.slice(asString.indexOf(' ') + 1, -1)
.toLowerCase()
)
)
) : asString;
};
}(Object, RegExp));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment