Created
May 8, 2014 08:54
-
-
Save holloway/1550f8f4705e0f4549d2 to your computer and use it in GitHub Desktop.
Co
This file contains 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 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