Last active
October 2, 2015 03:08
-
-
Save marlun78/2158447 to your computer and use it in GitHub Desktop.
Some type util methods.
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
/** | |
* Type Extras, version 1.0 | |
* Copyright (c) 2012, marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
*/ | |
(function (ns) { | |
// Returns an given element's internal [[Class]] property as a lower-case string | |
var _toString = Object.prototype.toString, | |
typeOf = function (object) { | |
return _toString.call(object).slice(8, -1).toLowerCase(); | |
}; | |
ns.isArguments = function (object) { | |
return typeOf(object) === 'arguments'; | |
}; | |
ns.isArray = function (object) { | |
return typeOf(object) === 'array'; | |
}; | |
ns.isFunction = function (object) { | |
return typeOf(object) === 'function'; | |
}; | |
ns.isNull = function (object) { | |
return typeOf(object) === 'null'; | |
}; | |
// Note! isNumber(NaN) will return true! | |
// Do detect if the object is a NaN value, | |
// use isNaN(object) or object !== object (Yes, NaN !== NaN is true!) | |
ns.isNumber = function (object) { | |
return typeOf(object) === 'number'; | |
}; | |
ns.isObject = function (object) { | |
return typeOf(object) === 'object'; | |
}; | |
ns.isString = function (object) { | |
return typeOf(object) === 'string'; | |
}; | |
ns.isUndefined = function (object) { | |
return typeOf(object) === 'undefined'; | |
}; | |
// Expose the typeOf() method | |
ns.typeOf = typeOf; | |
}(window.APP)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment