Skip to content

Instantly share code, notes, and snippets.

@leandrowd
Last active August 29, 2015 14:15
Show Gist options
  • Save leandrowd/6e979d7b1fc28ee4ba5a to your computer and use it in GitHub Desktop.
Save leandrowd/6e979d7b1fc28ee4ba5a to your computer and use it in GitHub Desktop.
Real type checking
// Real type checker
module.exports = function (object) {
return Object.prototype.toString.call(obj).slice(8, -1)
}
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