Skip to content

Instantly share code, notes, and snippets.

@marlun78
Last active October 2, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marlun78/2158447 to your computer and use it in GitHub Desktop.
Save marlun78/2158447 to your computer and use it in GitHub Desktop.
Some type util methods.
/**
* 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