Last active
August 29, 2015 14:04
-
-
Save FireNeslo/0e31d7cbc0c7935fe9de to your computer and use it in GitHub Desktop.
A better typeof function
This file contains hidden or 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(object) { | |
if(object && "name" in object.constructor) { | |
return object.constructor.name; | |
} | |
if(typeof object === 'number' && object !== object) { | |
return 'NaN'; | |
} | |
var type = Object.prototype.toString.call(object); | |
return type.substring(8,type.length-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment