Last active
August 29, 2015 14:15
-
-
Save leandrowd/6e979d7b1fc28ee4ba5a to your computer and use it in GitHub Desktop.
Real type checking
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
// Real type checker | |
module.exports = function (object) { | |
return Object.prototype.toString.call(obj).slice(8, -1) | |
} |
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
var checkType = require('./checkType'); | |
checkType({}); | |
// -> "Object" | |
checkType([]); | |
// -> "Array" | |
checkType(9); | |
// -> "Number" | |
checkType(''); | |
// -> "String" | |
checkType(new Date()); | |
// -> "Date" | |
checkType(function(){}); | |
// -> "Function"" | |
checkType(/regxp/); | |
// -> "RegExp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment