Created
March 24, 2015 13:32
-
-
Save leifoolsen/e1d3b75629c4969b5e4b to your computer and use it in GitHub Desktop.
Functions for working with type detection.
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
['Undefined', 'Null', 'Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Array', 'Object'].forEach( | |
function(name) { | |
var is = 'is' + name; | |
if(!window.is) | |
window[is] = function(obj) { | |
return ({}).toString.call(obj) === '[object ' + name + ']'; | |
}; | |
}); | |
(function() { | |
var a; | |
function x() { return isArguments(arguments) }; | |
console.debug("isUndefined(a) : " + isUndefined(a)); | |
console.debug("isNull(null) : " + isNull(null)); | |
console.debug("isFunction(x) : " + isFunction(x)); | |
console.debug("isString('A string') : " + isString("A string")); | |
console.debug("isNumber(1) : " + isNumber(1)); | |
console.debug("isNumber(1.1) : " + isNumber(1.1)); | |
console.debug("isDate(new Date()) : " + isDate(new Date())); | |
console.debug("isRegExp(/[a..z]/i) : " + isRegExp(/[a..z]/i)); | |
console.debug("isArray([1,2,3]) : " + isArray([1,2,3])); | |
console.debug("isObject({a:1,b:2,c:3}) : " + isObject({a:1,b:2,c:3})); | |
console.debug("isObject(new Object()) : " + isObject(new Object())); | |
console.debug("isArguments(arguments) : " + isArguments(arguments)); | |
console.debug("isArguments x(1, 2, {a:4, b:5}) : " + x(1, 2, {a:4, b:5})); | |
console.debug("isArguments x({a:4, b:5}) : " + x({a:4, b:5})); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment