Skip to content

Instantly share code, notes, and snippets.

@qzm
Created March 20, 2017 15:44
Show Gist options
  • Save qzm/e333d2e3c68bc43b36ca6932657a748d to your computer and use it in GitHub Desktop.
Save qzm/e333d2e3c68bc43b36ca6932657a748d to your computer and use it in GitHub Desktop.
type javascript object
'use strict';
var getType = function (obj) {
return Object.prototype.toString.call(obj).match(/\[object (\w+)\]/)[1];
};
isString = function () {
return getType(this) === 'String';
};
isArray = function () {
return getType(this) === 'Array';
};
isObject = function () {
return getType(this) === 'Object';
};
isFunction = function () {
return getType(this) === 'Function';
};
isNumber = function () {
return getType(this) === 'Number';
};
isRegExp = function () {
return getType(this) === 'RegExp';
};
isUndefined = function () {
return getType(this) === 'Undefined';
};
isNull = function () {
return getType(this) === 'Null';
};
isBoolean = function () {
return getType(this) === 'Boolean';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment