Created
March 20, 2017 15:44
-
-
Save qzm/e333d2e3c68bc43b36ca6932657a748d to your computer and use it in GitHub Desktop.
type javascript object
This file contains hidden or 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
'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