Skip to content

Instantly share code, notes, and snippets.

@webbower
Created August 19, 2014 23:24
Show Gist options
  • Save webbower/90b06f72c8067541ae6a to your computer and use it in GitHub Desktop.
Save webbower/90b06f72c8067541ae6a to your computer and use it in GitHub Desktop.
Value testing functions
function existy(val) {
return val !== undefined && val !== null && !isRealNaN(val);
}
function toClass(obj) {
return Object.prototype.toString.call(obj);
}
function isMaker(type) {
return function(val) {
return toClass(val).slice(8, -1) === type;
}
}
var isFunction = isMaker('Function');
var isString = isMaker('String');
var isNumber = isMaker('Number');
var isArguments = isMaker('Arguments');
function isRealNaN(val) {
return isNumber(val) && val != +val;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment