Skip to content

Instantly share code, notes, and snippets.

@holloway
Created May 8, 2014 08:54
Show Gist options
  • Save holloway/1550f8f4705e0f4549d2 to your computer and use it in GitHub Desktop.
Save holloway/1550f8f4705e0f4549d2 to your computer and use it in GitHub Desktop.
Co
var is = {
get_type: function(thing){
if(thing===null) return "[object Null]";
else if(thing!==thing) return "[object NaN]";
return Object.prototype.toString.call(thing);
},
compare: function(type){
return function(value){
return this.get_type(value) === "[object " + type + "]";
};
}
};
(function(is, types){
types.map(function(type){is[type]=is.compare(type);});
}(is, ["Array","Object","Number","String","Undefined","Null","Boolean","NaN"]));
is.Array([1]) // true
is.Object({a:1}) // true
is.Number(1) // true
is.String("test") // true
is.String("") // true
is.Undefined(undefined) // true
is.Null(null) // true
is.Boolean(true) // true
is.Boolean(false) // true
is.Boolean(1) // false
is.NaN(NaN) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment