Last active
December 17, 2015 06:38
-
-
Save RockyMyx/5566430 to your computer and use it in GitHub Desktop.
JavaScript: typeOf.js
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 typeOf(obj) { | |
var _toString = Object.prototype.toString; | |
var _type ={ | |
"undefined" : "undefined", | |
"number" : "number", | |
"boolean" : "boolean", | |
"string" : "string", | |
"[object Function]" : "function", | |
"[object RegExp]" : "regexp", | |
"[object Array]" : "array", | |
"[object Date]" : "date", | |
"[object Error]" : "error" | |
} | |
return _type[typeof obj] || _type[_toString.call(obj)] || (obj ? "object" : "null"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment